"Monogodb" The high update operation of MongoDB

Source: Internet
Author: User

The last four blogs, we talked about the high query operation of MongoDB. Now on this blog let's know about the high update operation about MONODB.

1. Saveas for Save (), whose function was to update the existing record and to create the new record.
Grammar:db.mycollection.save (x);
2. General Operation2.1 $inc Grammar: {$inc: {Field:value}}
Function:add the value to the certain field.
Example

2.2 $Set and $unset {$set: {Field:value}}/{$unset: {field:1}}
Function:set the field value, if the field does not exist, then add the new field, and value would support all the type.


2.3 $push, $pushAll, $addToSet {$push: {Field:value}}
Function:if The field is a existing Arry, this function would add the value to the end.  If filed doesnot exist, it'll add the new field, and then set the field value. If field does exists but is not an array, it would throw the error.
$pushAll: {$pushAll: {Field:value_array}}
This function is the same as $push and only the Value_array is array.
$addToSet: {$addToSet: {Field:value}}


2.4 $pop and $pull $pullAll

2.5 $rename {$rename: {old_friend_name:new_field_name}}



"Monogodb" The high update operation of MongoDB

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.