Insert: usekeke automatically generates the keke database after data is written. J {name: mongo };{ name: mongo} t {x: 3 };{ x: 3} db. things. save (j); db. things. save (t); query db. things. find (); {_ id: ObjectId (4c2209f9f3924d31102bd84a), name: m
Insert: use keke automatically generates the keke database after data is written. J = {name: "mongo" };{ "name": "mongo"} t = {x: 3 };{ "x": 3} db. things. save (j); db. things. save (t); query db. things. find (); {"_ id": ObjectId ("4c2209f9f3924d31102bd84a"), "name": "m
Insert:
Use keke
The keke database is automatically generated after data is written.
> J = {name: "mongo" };{ "name": "mongo" }> t = {x: 3 };{ "x": 3}> db. things. save (j);> db. things. save (t );
Query
> Db. things. find (); {"_ id": ObjectId ("4c2209f3924d31102bd84a"), "name": "mongo"} {"_ id": ObjectId ("4c2209fef3924d31102bd84b "), "x": 3}
> Var cursor = db. things. find ();> while (cursor. hasNext () printjson (cursor. next (); {"_ id": ObjectId ("501c7e5cab2f3c46faf8e68a"), "name": "mongo"} {"_ id": ObjectId ("objective "), "x": 3}
ForEach () must define a function for each cursor element to call. forEavh is case sensitive, Hong Kong Space, javascript is case sensitive.
> Db. things. find (). forEach (printjson); {"_ id": ObjectId ("501c7e5cab2f3c46faf8e68a"), "name": "mongo"} {"_ id": ObjectId ("external "), "x": 3}
We can also use the cursor as an array:
> Var cursor = db. things. find ();> printjson (cursor [1]); {"_ id": ObjectId ("501c7e65ab2f3c46faf8e68b"), "x": 3}>
The following example converts a cursor to a real array type:
> Var arr = db. things. find (). toArray ();> arr [1] {"_ id": ObjectId ("501c7e65ab2f3c46faf8e68b"), "x": 3}>
, U.S. server, Hong Kong server rent