View all databases
Show DBS
Switch Database (automatically created if not present)
Use DatabaseName
Delete current Database
Db.dropdatabase ()
There are no tables in MongoDB, only collections.
Insert Collection
Db. Collection name. Insert (JSON)
For example Db.connection.insert ({x:1})
For loop insertion (JS syntax)
for (i=3;i<100;i++) DB. Name of the function. Insert ({x:i})
View all Collections
Show collections
View All data
Db. Collection name. Find ()
View data that meets your criteria
Db. Collection name. Find ({x:1})
Viewing the number of data bars
Db. Collection name. Find (). Count ()
Jump over N bar data
Db. Collection name. Find (). Skip (3)
View Top N Data
Db. Collection name. Find (). Limit (2)
Sort
Db. Collection name. Find () sort ({key:1}) sorted by the value of key, 1 is ascending, 1 is descending
Full update (Old data is updated by new data)
Find data x 1 and update to x 9
Db. Collection name. Update ({x:1},{x:9})
Partial Update (there is a field that is updated and no fields remain intact)
Find to X=1,y=3; update x to 3,y remains unchanged
Db. Collection name. Update ({x:1,y:3},{$set: {x:3}})
Update + Create (If the lookup data does not exist, it is created automatically)
Db. Collection name. Update ({X:1},{x:2},true}
more than one update (If you find more than one qualifying data, all updates, be sure to use the $set identifier)
Db. Collection name. Update ({x:1},{$set: {x:2}},false,true}
Delete
Db. Collection name. Remove ({x:1})
Delete Collection
Db. Collection name. Drop ()
"MongoDB" additions and deletions to check the basic operation