Read
Db.collection.find ()
Db.users.find (
{age: {$gt:}},
{name:1, address:1}
). Limit (5). Sort ({age:1})
Users are collection names and are searched from users;
Age is the criteria for query, the result of which is the value of the Lookup name field is greater than 18;
Name is projection, the filter column (1 is present, 0 represents nonexistent), and represents the value in the returned result that contains the NAME,ADDRESS,_ID (Default include field) field;
Limit is cursor modifier, the representative returns up to 5;
Sort is sorted by the value of age.
Note:
1. All inquiries can only be directed to a single collection;
2. The query results are not sorted unless the sort is used;
Db.collection.findOne () is the return of a value.
Db.collection.find () returns the cursor type.
Insert
Db.collection.insert ()
Db.users.insert (
{
name: "Sue",
age:22,
Status: "A"
}
)
Note:
1. If there is no _id property in the INSERT statement, Mongod automatically adds a _id property and produces a unique value, ObjectId.
2. If you have the _id property in the INSERT statement, you must ensure that its value is unique and, if repeated, returns an exception.
3. Update () and save () operations can also implement the Insert function.
Update
Db.collection.update () or Db.collection.save ()
Db.users.update (
{age:{$gt:}}, --update criteria
{$set: {status: ' A '}}, --update action
{ Multi:true} --update option
)
Note:
1. By default, the Update method updates only one document, but if you set the multi argument to True, you can update all compliant documents
2. The Save method can only update a single document
Delete
Db.collection.remove ()
Db.users.remove (
{status: "D"} --remove criteria
)
Note:
1. By default, the Remove method deletes all documents that meet the criteria