MongoDb Add + delete field to table

Source: Internet
Author: User
Tags mongodb add

MongoDB uses the update () and Save () methods to update the documents in the collection

Parameter description:

    • Query: The search condition for update, similar to where in SQL update query.
    • Update: Update object and some updated operators (such as $, $inc ... ) can also be understood as the SQL update query within the set after the
    • upsert : Optional, this parameter means that if there is no record of update, insert objnew,true as INSERT, default is False, do not insert.
    • multi : Optional, mongodb default is False, only update the first record found, if this parameter is true, will be found on the condition of a number of records update all.
    • writeconcern : Optional, throws an exception level.

1. Add a field. Table represents the name of the sheet, adds a field type, an integer type, and a value of 1.

Db.getcollection (' article '). Update ({}, {$set: {type:numberint (' 1 ')}}, {multi:true})

2. Delete a field

Db.getcollection (' article '). Update ({},{$unset: {content: ""}},false, True)

Transferred from: https://www.cnblogs.com/crystaltu/p/6932377.html

MongoDb Add + delete field to table

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.