I. Preparation
1. Find (I like to call it a service port. If it appears below, it is called a service port.), Double-click to start;
2. Restart (I call it an operation port. If it appears below, it is an operation port.)
3. md data \ dB (Create a database named DB under the Data Directory), use dB (use this database)
II,Start
1. Create
Mongo uses the keyword insert to create a file and add it to a container. For example:
We want to save a blog post. First, we create a local variable post with the key "title", "content", and
"Date", enter the following code in the operation port and press ENTER
> Post = {"title": "My blog post ",
... "Content": "Here's my blog post .",
... "Date": new date ()}
{
"Title": "My blog post ",
"Content": "Here's my blog post .",
"Date": "sat Dec 12 2009 11:23:21 GMT-0500 (EST )"
}
Enter
> DB. Blog. insert (post)
2. Read
Use the keyword find or findone
Enter
> DB. Blog. Find () or db. Blog. findone () (Note: Please clarify the differences between them)
The result of searching for files in the container blog is as follows:
{
"_ Id": objectid ("4b23c3ca7525f35f94b60a2d "),
"Title": "My blog post ",
"Content": "Here's my blog post .",
"Date": "sat Dec 12 2009 11:23:21 GMT-0500 (EST )"
}
3. Update
To update a file, we must have two parameters. First, we must know which file to update and then what file to update. Suppose we want to add an array for storing comments to the blog post. First, we need to modify the post variable. we add a key to the post variable and enter it in the operation port.
> Post. Comments = []
Then execute the update statement.
> DB. Blog. Update ({Title: "My blog post"}, post)
Execute the find statement to see the changes.
> DB. Blog. Find ()
4. Delete
Enter
> DB. Blog. Remove ({Title: "My blog post "})
Delete the post we just put in the container.
For more information, see:Http://docs.mongodb.org/manual/core/read-operations/#queries-in-mongodb
Please point out any errors. Thank you!