MongoDB Learning Notes < two >

Source: Internet
Author: User
Tags bulk insert modifier

Continue with the shell of the study, and continue to learn the following knowledge:

--Document data insertion

--Document Data deletion

--Document Data Update

Specific as follows:

1. Inserting a document

Db.person.insert ({"Name": "Xiaoming"})

2. BULK INSERT

Use the For loop to do this, such as:

for (Var i=0;i<10;i++){

Db.person.insert ({"Name": i})

}

3.save operation

Similar to the insert operation, the Save action differs from the insert operation in that the insert operation will error if "_id" is encountered, and the Save action will be updated

4. Delete all data in the collection

Db.person.remove (), the collection itself and the index are not deleted.

5. Delete by condition

Db.person.remove ({"Name": "Xiaoming"})

6. Tips

If you want to delete a collection that clears a very large amount of data, deleting the collection directly and re-indexing is much more efficient than using the Remove method directly.

7. Document Update operations

Db. Document name. Update ({finder},{modifier})

For example: Db.person.update ({"Name": "Xiaoming"},{$set: {"name": "Xiaohong"}})

8.insertOrUpdate operation

Db. Document name. Update ({finder},{modifier},true)

If the query detects the document, it is updated, and if it is not found, the insert operation

9. Batch update operations

if it is: db. The document name. Update ({query},{modifier}) modifies only the first document to which the update query is made, not all updates

So, take the following approach: DB. Document name. Update ({finder},{modifier},false,true)





MongoDB Learning Notes < two >

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.