This article mainly introduces MongoDB database additions and deletions to check operation.
Increase
MongoDB, like other relational databases, uses insert to add data to the collection.
db.collectionName.insert(内容)
Show all collections in the database:
show collections
Delete
In MongoDB, remove removes documents that meet certain criteria in the collection.
Remove accepts a number of parameters. As a condition to find the document to delete:
Of course, it is also possible to delete an entire collection directly by dropping the method:
db.person.drop()
Deleting a collection and then rebuilding the index is faster than deleting all the documents in the collection.
Change
The change operation is more complex than adding and deleting, since MongoDB is not only able to use the Update method, but also can use a lot of auxiliary churn, we first say the Update method.
Update
The Update method accepts two parameters, the first of which is to find the document's qualifications, and the second new document that needs to be changed:
In the above update ({“name”:”liufang”},post)
, the equivalent of the inference condition in the where in the name:liufang
relational database, and post is relative to the running content after the SET statement.
The simplest thing to update is to use a new document instead of a matching document, which is suitable for a time when the pattern structure has changed significantly. For example, the following documents:
{ "name":"tyq", "age":22, “date”:newDate()}
Change to:
{ "name":"tyq", “age”:22, “friends”:”liufang”}
For example, with:
Change Device
Let's talk about MongoDB's powerfulChange Device。
MongoDB has some auxiliaryChange Device。 Example inc, Set u n s Span class= "Mi" id= "mathjax-span-1075" style= "Font-family:mathjax_math; Font-style:italic; " >e t unset p u MongoDB increase and deletion check (a)