Basic statement usage method of MongoDB database
Query: MySQL: SELECT * FROM user Mongo: db. user. find() Conditional query: MySQL: SELECT * FROM user WHERE name = ’starlee’ Mongo: db.user.find({‘name’ : ’starlee’}) Insert: MySQL: INSERT INOT user (`name`, `age`) values (‘starlee’,25) Mongo: db.user.insert({‘name’ : ’starlee’, ‘age’ : 25}) If you want to add a field in MySQL, you must: ALTER TABLE user…. But in MongoDB you just need: db.user.insert({‘name’ : ‘starlee’, ‘age’ : 25, ’email’ : ‘ [email protected]’}) Delete: MySQL: DELETE * FROM user Mongo: db.user.remove({}) Conditional deletion: MySQL: DELETE FROM user WHERE age < 30 Mongo: db.user.remove({‘age’ : {$lt : 30}}) MongoDBSize comparison symbols in : $gt : > $gte : >= $lt : < $ lte : <= $ne : != UPDATEUpdate: MySQL: UPDATE user SET `age` = 36 WHERE `name` = ’starlee’ Mongo: db.user.update({‘name’ : ’starlee’}, {$set : {‘age’ : 36}}) Update with operations: MySQL: UPDATE user SET `age` = `age` + 3 WHERE `name` = ‘starlee’ Mongo: db.user.update({‘name’ : ’starlee’}, {$inc : {‘age’ : 3}}) countTotal: MySQL: SELECT COUNT(*) FROM user WHERE `name` = ’starlee’ Mongo: db.user.find({‘name’ : ’starlee’}).count() It can also be written like this: db.user.count({‘name’:’starlee’}) LIMITclause: MySQL: SELECT * FROM user limit 10,20 Mongo: db.user.find().skip(10).limit(20) INclause: MySQL: SELECT * FROM user…