Read
Db.collection.find ()
db.users.find ( }}, 1 1 }). Limit (5). Sort ({age:1})
Users are collection names and are searched from users;
The age is the query criteria, filtering results, representing the value of the Lookup name field is greater than 18;
Name is projection, the filter column (1 for presence, 0 for non-existent), represents the value of the name,address,_id (default included field) field in the returned result;
Limit is the cursor modifier, which represents a maximum of 5 returns;
Sort is sort, 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 you use sort;
Db.collection.findOne () is a value returned.
Db.collection.find () returns the cursor type.
Insert
Db.collection.insert ()
Db.users. Insert ( { name: "Sue", age :$, Status: "A" })
Note:
1. If the INSERT statement does not have the _id property, Mongod automatically adds a _id property and produces a unique value, ObjectId.
2. If the INSERT statement has the _id attribute, it must be guaranteed that its value is unique and, if repeated, an exception is returned.
3. The 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 parameter to True, you can update all documents that are compliant
2. The Save method can only update one single document
Delete
Db.collection.remove ()
Db.users.remove ( {status: "D"} --Remove criteria)
Note:
1. By default, the Remove method removes all documents that meet the criteria