---restore content starts---
Database operations are generally crud, the most difficult of which is the query, all of us first to understand the MongoDB
Inserting (insert)
When it comes to insertions, we have to talk about how to create a database, how to create a collection, and then how to create a document.
The set mentioned here is the table in the relational database, and the document is (Row).
Now all we have to do is create a flast database, create a M collection, and insert a document.
Updates (update)
Let's start with a simple update:
We now want to name: "Xu" into name: "Joe", age:23
We can see the three properties shown in the Red box
nmatched: Represents the number of captures
nupserted: Represents the number of insertions
nmodified: Represents the number of modifications
Now let's look at the real syntax of update
Db.collection.update (<Query>, <Update>, {upsert:<Boolean>, (false) whether to insert multi when it does not exist:<Boolean>, (false) whether to select multiple Writeconcern:<Document>exception level})
To demonstrate the above three optional parameters and explain the updated parameters, we need to add a document
Demonstration of the first Upsert (false)
Demonstration of the second multi (false)
The following code is then available:
From the above we can also see the capture of two, modified two,
We can also use the findandmodify command to modify
With this command we can clearly see which documents have been modified and of course not recommended, loss performance
By the way, what are the commands for "findandmodify":
> Query statement
> UPDATE statement to update only the first statement found
> Remove (Boolean) is removed
>New (Boolean) represents whether to return to the pre-update or post-update, the default is the pre-update, from the above value can be seen
Delete Remove
Delete Of course is relatively simple now, look directly at the grammar bar!
Db.collection.remove (<Query>,(optional) Delete the condition of the document {justone:<Boolean>,(optional) If set to TRUE or 1, only one document is deleted. Writeconcern:<Document>(optional) the level at which the exception is thrown. })
Take a look at the example
QueryFind
Queries are generally the hardest part, because there are a lot of logic that we learn from the simplest:
For example, we want to query the Name= "Jack" document.
Can see that we have nothing to find, but I believe that with the above changes to this must be understandable,
Our focus is to understand the $ directive
---restore content ends---
MongoDB Quick Start