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 >