Monogdb Notes 1

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.