MongoDB Learning notes < two >

Source: Internet
Author: User
Tags bulk insert

Continuing to have shell lore, they continue to study the examples of the following knowledge:

--Document data insertion

--Document Data deletion

--Document Data Update

For more information, like the following:

1. Inserting a document

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

2. BULK INSERT

Use for loop to do, for example:

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

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

}

3.save operation

Like the insert operation, the difference between the save operation and the insert operation is that the insert operation will have an error if the "_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 based on conditions

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

6. Tips

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

7. Document Update operations

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

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

8.insertOrUpdate operation

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

If the Finder has a document, it is updated, and if it is not found, the insert operation

9. Batch update operations

The assumption is: db. The document name. Update ({Finder},{}) only changes the first document to the update query, not all of them .

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





Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

MongoDB Learning notes &lt; two &gt;

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.