1Comparison of:d B.collection.remove () and Db.collection.drop () Insert 1 million test data for(Var i=0;i<1000000; i++) {Db.tester.insert ({'Foo':'Bar'+i,"Baz:"I"Z":Ten-i})} Methods for deleting operations 1var timeremoves=function() {var start=(New Date ()). GetTime (); Db.tester.remove (); Db.tester.findOne (); var end=(New Date ()). GetTime (); var Timediff= end-start; Print ("spents:"+timediff+"milliseconds");} Timeremoves () test>timeremoves () spents: 5398 ms method 2test>Db.tester.drop ()trueInstant Completion2: The use of modifiers (1$inc is used to increase the value of an existing key, or if the key does not exist, create one. Db.user.update ({'name':'Zhangsan'}, {'$inc':{' Age':1}}, {multi:true })(2$set $set is used to specify the value of a field, and if the field does not exist, it is created. Db.user.update ({'name':'Zhangsan'}, {'$set':{'Address':'Qingdao'}}, {multi:true}) db.blog.update ({'_id':' One'}, {'$set':{"'}}) You can use $set to modify the inline document for example: Test>db.user.findone ({'name':'Wangwu'}){ "_id": ObjectId ("54BBB0506D5990C21F435BCD"), "Address" : { " City":"Qingdao" }, " Age": -, "name":"Wangwu", "Sex":true}test>db.user.update (... {'name':'Wangwu'},... {'$set':{'address.city':'Qingdao'}}... ) Test>db.user.findone ({'name':'Wangwu'}){ "_id": ObjectId ("54BBB0506D5990C21F435BCD"), "Address" : { " City":"Qingdao" }, " Age": -, "name":"Wangwu", "Sex":true}(3) $unset to remove a key value Db.user.update ({'name':'Zhangsan'}, {'$unset':{'Address':1}}, {multi:true})
Monogdb Notes 1