[MongoDB] Remove, update, create document

Source: Internet
Author: User


Remove the wand with the from our name "Doom Bringer" wands collection.

Db.wands.remove ({name: "Doom bringer"})>> writeresult ({' ngremoved ': 1})

When we removed "Doom Bringer" the wand, we noticed that it had a power "Death" of, and we don ' t want any wands as that in our data Base. To is safe, let's remove any wands containing the in their powers .

Db.wands.remove ({name: "Doom bringer", Powers: "Death"})


Write the command to update the wand with a in and set the to name "Devotion Shift" price 5.99 .

Db.wands.update ({name: "Devotion Shift"},{"$set": {price:5.99}});

Update all the document: "multi"

Increase level_required by 2, apply to all of the documents match {powers: "Fire"}:

db.wands.update (  "Fire"},  {"$inc": {level_required:2}},  {true })

Create New Document If there is no existing one: "upsert"

db.logs.update (  "Dream Bender"},  {"$inc": {count:1}},  {True })

[MongoDB] Remove, update, create document

Related Article

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.