insert
db.users.insert([{"name":"张三","age":18,"status":1},{"name":"李四","age":20,"status":0}]);
insertOne
db.users.insertOne({"name":"王五","age":22,"status":1});
insertMany
db.users.insertMany([{"name":"李六","age":24,"status":1},{"name":"陈真","age":27,"status":1}]);
db.users.findOne({});
查全部
db.schools.find({});
in查询
db.users.find({"age":{$in:[18,20]}});
and查询
db.users.find({"age":22,"status":1});
or查询
db.users.find({$or:[{"name":"李四"},{"age":27}]});
and,or
db.users.find({"status":1,$or:[{"name":"王五"},{"age":27}]});
updateOne
db.users.updateOne({"name":"张三"},{$set:{"age":20}});
updateMany
db.users.updateMany({"age":20},{$set:{"age":25},$currentDate:{lastModified:true}});
update
db.users.update({"status":1},{$set:{"age":21}},{multi:true});
deleteOne
db.users.deleteOne({"name":"陈真"});
deleteMany
db.users.deleteMany({"name":{$in:["王五","张三"]}});
remove
db.users.remove({"status":1},{justOne:true});
db.users.remove({"status":1});