MongoDB modifier (3)

Source: Internet
Author: User
Tags modifier

1. Update

Db.persons.update ({name: "Caohui"},{id:2}); update only one, replace update directly

Db.persons.update ({name: "Caohui"},{id:2},true), update only one, replace update directly, insert if not present

2. Full-scale update

Db.persons.update ({name: "Caohui"},{$set: {id:2}},false,true); full-scale local update

3. $set {$set: {Field:value}}

It is used to specify a key value pair, if there is a key value is modified, does not exist to add

4. $inc {$inc: {Field:value}}

Only used with numeric types, you can add and subtract numeric types that correspond to the specified key

5. $unset {$unset: {field:1}} to delete the corresponding key value

6. $push {$push: {Field:value}}

Add data to the array, or create if the key does not exist

7. $pushAll {$push: {Field:[value]}}

Adding elements to an array in bulk

8. $addToSet {$addToSet: {Field:value}}

Add elements to the array, if present, without adding

9. $pop {$pop: {Field:value}}

Delete data to an array, 1 delete the last value;-1 Delete the first value

Ten. $pull {$pull: {Field:value}}

Deletes the value specified by the array

$pullAll {$pullAll: {Field:value}}

To delete multiple corresponding array values

12. Array Locator $

Db.books.update ({"Boook.type": "JS"},{$set: {"Boook.$.count": 222}})

MongoDB modifier (3)

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.