1. Switch database
Admin database: Use admin
Test database: Use test
2. Added:
Method One (preferred)
c={Name="Junior", Teacher: "Xiao Zhang", stucount: db.class. Save (c) or Db.class. Insert (c)
Method Two
Db.class. Insert ({name: "The Junior", Teacher: "Xiao Zhang", stucount:)
Note that saving the same will prompt objectid cannot be repeated
3. Delete
Db.class.remove ({name: "the"})
4. Modification
Modify the Teacher field value (only one that satisfies the condition is modified)
Db.class. Update ({name: "},{$set: {name:" Teacher "," Hehhe ", Stucount:]})
Modify all that meet the criteria
Db.class. Update ({name: "},{$set: {name:" Teacher "," tt ", Stucount:}},{multi:true})
Another update is less than the new
Db.class. Update ({name: "},{$set: {name:" Teacher "," Hehhe ", Stucount:}},{upsert:true})
5. Enquiry
Without any conditions
Db.class.find ()
Query the "name=" data
Db.class.find ({name: "the"})
Querying all data for stucount>10
Db.class.find ({"Stucount", {$gt:ten})
Query the first piece of data for stucount<5
Db.class.findOne ({"Stucount": {$lt:5}})
Querying the 10>STUCOUNT>5 data
Db.class.find ({"Stucount": {$lt:ten, $gt:5}})
Paging Query
Db.class.find (). Skip.Limit (5)
How many data are queried
Db.class.find (). Count ()
How many data are queried to satisfy a condition
Db.class.find ({"Stucount", {$lt:ten}}). Count ()
The current number of queries in a paged query
Db.class.find (). Skip ((). Limit (ten). Count (true)
**count () does not write ture, is the total number
To query using cursors:
Traverse all
var cursor = Db.class.find () while (cursor. Hasnext ()) Printjson (cursor. Next())
Use cursor subscript (overflow may occur)
var cursor = Db.class.find () cursor [1]
Using the array subscript
var arr=db.class.find (). ToArray () arr[1]
foreach Output
Db.class.find (). ForEach (Printjson)
It's not written in the back of the set with conditions.
MongoDB first knowledge-adding and deleting changes