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 < two >