We should first know the data structure of MongoDB: MongoDB: Library----Collection-->json Object
View
Show DBS//See which libraries are available
Show collections//See which collections are in the library
Library operations
Use library name//using a library, entering a library, creating a library
Library name. Dropdatabase ()//delete
Collection operations
The collection is added to the difference operation.
Db. Collection name. Insert (XX)//create collection Insert record
Db. Collection name. Drop ()//delete collection
Db. Collection name. Find ()//query
Db. Collection name. Update ()//Updates
Db. Collection name. Remove ()//delete
Add action
Insert a single record
Db.dept.insert ({"Deptno": Ten, "Dname": "Java"})
Inserting multiple records
Db.dept.insert ([{"Deptno": Ten, "Dname": "java"},{"Deptno": "Dname": "Java EE"}])
Query operations
Querying All records
Db.dept.find ()
Querying the records of deptno=10
Db.dept.find ({"Deptno": 10})
Query deptno>20 Records (other $gte, $lt, $lte, $ne)
Db.dept.find ({"Deptno": {$gt: 20}})
Query Dname records starting with the J letter
Db.dept.find ({"Dname":/^j/})
Query for records with a in dname
Db.dept.find ({"Dname":/a/})
Delete operation
Delete a deptno=10 record
Db.dept.remove ({"Deptno": 10})
Delete all records
Db.dept.remove ({})
Update action
Update all, the entire JSON object will be covered out
Db.dept.update ({"Deptno": 30},{"Phone": "1354444444"})
Partial update, modifying a property value
Db.dept.update ({"Deptno": 30},{$set: {"Phone": "1354444444"}})
Statistical operations
Total number of statistics records
Db.dept.count ()
Count the number of records that match the criteria
Db.dept.count ({"Dname": "Java"})
Paging operations
means skip the top 5, take the last 5
Db.user.find (). Skip (5). Limit (5)
Some operations commands for "MongoDB" MongoDB