Operation Record and summary:
Show DBS
Use some_db (a DB is selected as well as a new db "Note to write data, new some_db cannot be empty")
Show collections
$inc
> db.simple.find () { "_id" : objectid ("54E9DC1FA4C00BA20F4432AD"), "name"  : "ABC", "Age" : 12 }{ "_id" : objectid ("54e9dc37a4c00ba20f4432ae"), "name" : "BCD", "Age" : 13 }{ "_id" : objectid (" 54e9dc52a4c00ba20f4432af "), " name " : " CDE ", " Age " : 14 }{ " _id " : objectid ("54e9dc64a4c00ba20f4432b0"), "name" : "def", "Age" : 16 }{ "_id" : objectid ("54e9dc75a4c00ba20f4432b1"), "name" : "def", "Age"  : 656 }> db.simple.update ({"Name": "abc"},{$inc: {"Sex": "None"}}) Writeresult ({"nmatched"  : 0, "nupserted" : 0, "nmodified" : 0, "Writeerror" : {"code" : 14, " ErrMsg " : " cannot increment with non-numeric argument: {sex: \ "none\"} "}}) > db.simple.update({"Name": "abc"},{$inc: {"Age": 50}}) Writeresult ({ "nmatched" : 1, "nupserted" : 0, "nmodified" : 1 }) > db.simple.find () { "_id" : objectid ("54E9DC1FA4C00BA20F4432AD"), "name" : "abc", "Age" : 62 }{ "_id" : objectid (" 54e9dc37a4c00ba20f4432ae "), " name " : " BCD ", " Age " : 13 }{ " _id " : objectid ("54e9dc52a4c00ba20f4432af"), "name" : "CDE", "Age" : 14 }{ "_id" : objectid ("54e9dc64a4c00ba20f4432b0"), "name" : "def", "Age"  : 16 }{ "_id" : objectid ("54e9dc75a4c00ba20f4432b1"), "name" : "Def", "Age"  : 656 }
Summary: $inc can only be followed by numbers, for numeric increments
$set
> db.simple.update ({"Name": "abc"},{$set: {"Sex": "None"}}) Writeresult ({"nmatched": 1, "nupserted": 0, "nmodified": 1}) > Db.simple.find () {"_id": ObjectId ("54E9DC1FA4C00BA20F4432AD"), "name": "ABC", "Age":, "Sex": "None"} {"_i D ": ObjectId (" 54e9dc37a4c00ba20f4432ae ")," name ":" BCD "," Age ":} {" _id ": ObjectId (" 54e9dc52a4c00ba20f4432af ")," NA Me ": CDE", "Age": +} {"_id": ObjectId ("54e9dc64a4c00ba20f4432b0"), "name": "Def", "Age": +} {"_id": ObjectId ("5 4e9dc75a4c00ba20f4432b1 ")," name ":" Def "," Age ": 656}>
Summary: $set can be a string or something like that
$in, $or, $nin
> db.simple.find ({"wife": {$in: ["JC"]}}) { "_id" : objectid ("54ec289e560c1ea13477ce89"), "name" : "Xul", "wife" : [ "JC", "Juhua" ] }{ "_id" : objectid ("54ec28b8560c1ea13477ce8a"), "name" : "Jack", "wife" : [ "JC", "Huangrui" ] }> db.simple.find ({"wife": {$nin: ["JC"]}}) { "_id"  : objectid ("54E9DC1FA4C00BA20F4432AD"), "name" : "abc", "Age" : 62, " Sex " : none" }{ "_id" : objectid ("54e9dc52a4c00ba20f4432af"), "name" : "CDE", "Age" : 14 }{ "_id" : objectid ("54e9dc64a4c00ba20f4432b0"), "Name" : "def", "Age" : 16 }{ "_id" : objectid (" 54e9dc75a4c00ba20f4432b1 "), " name " : " def ", " Age " : 656 }{ " _id " : objectid ("54ec259d560c1ea13477ce85 "), " name " : " def ", " Age " : 14 }{ " _id " : objectid (" 54ec25ac560c1ea13477ce86 "), " name " : " abc ", " Age " : 16 }> Db.simple.find ({"wife": {$in: ["Huangrui"}}) { "_id" : objectid ("54ec28b8560c1ea13477ce8a"), "name" : "Jack", "wife" : [ "JC", "Huangrui" ] }> Db.simple.find ({"wife": {$in: ["Juhua"}}) { "_id" : objectid ("54ec289e560c1ea13477ce89"), " Name " : xul", "wife" : [ "JC", "Juhua" ] }> Db.simple.find ({$or: [{"Age": 14},{' age ': +}]}) { "_id" : objectid ("54e9dc52a4c00ba20f4432af"), "name" : "CDE", "Age" : 14 }{ "_id" : objectid (" 54e9dc64a4c00ba20f4432b0 "), " name " : " def ", " Age " : 16 }{ " _id " : objectid ("54ec259d560c1ea13477ce85"), "NAMe " : " def ", " Age " : 14 }{ " _id " : objectid (" 54ec25ac560c1ea13477ce86 "), " name " : " abc ", " Age " : 16 }> > > db.simple.find ({"wife": {$nin: ["JC"]}}) { "_id" : objectid (" 54E9DC1FA4C00BA20F4432AD "), " name " : " abc ", " Age " : 62, " Sex " : " None " }{ " _id " : objectid (" 54e9dc52a4c00ba20f4432af "), " name " : " CDE ", "Age" : 14 }{ "_id" : objectid ("54e9dc64a4c00ba20f4432b0"), "name" : "def", "Age" : 16 }{ "_id" : objectid (" 54e9dc75a4c00ba20f4432b1 "), " name " : " def ", " Age " : 656 }{ " _id " : objectid ("54ec259d560c1ea13477ce85"), "name" : "def", "Age" : 14 }{ "_id" : objectid ("54ec25ac560c1ea13477ce86"), "name" : "aBC ", " Age " : 16 }{ " _id " : objectid (" 54ec38ab560c1ea13477ce8b "), " name " : " JC ", " hus " : [ " shit " ] }{ " _id " : objectid (" 54ec38be560c1ea13477ce8c "), " name " : " Juhua ", " wife " : [ " shit " ] }>
Don't care about the wonderful data!
Summary: Nothing to say, is no $not
Count
> Db.simple.count ({"Age": +}) 2> Db.simple.count ({"Age": 16}) 2
Distinct: Go heavy
> db.simple.find () { "_id" : objectid ("54E9DC1FA4C00BA20F4432AD"), "name"  : "ABC", "Age" : 62, "Sex" : "None" }{ "_id" : objectid ( "54e9dc52a4c00ba20f4432af"), "name" : "CDE", "Age" : 14 }{ "_id" : objectid ("54e9dc64a4c00ba20f4432b0"), "name" : "def", "Age" : 16 }{ "_id" : objectid ("54e9dc75a4c00ba20f4432b1"), "name" : "def", "Age"  : 656 }{ "_id" : objectid ("54ec259d560c1ea13477ce85"), "name" : "Def", "Age" : 14 }{ "_id" : objectid ("54ec25ac560c1ea13477ce86"), "name" : "abc", "Age" : 16 }{ "_id" : objectid (" 54ec289e560c1ea13477ce89 "), " name " : " Xul ", " wife " : [ " JC ", " Juhua " ] }{ "_id" : objeCtId ("54ec28b8560c1ea13477ce8a"), "name" : "Jack", "wife" : [ "JC", " Huangrui " ] }> db.simple.disinct (" age) 2015-02-24t16:14:03.415+0800 syntaxerror: Unexpected token illegal> db.simple.disinct ("Age") 2015-02-24t16:14:05.554+0800 typeerror: property ' disinct ' of object name.simple is not a Function> db.simple.distinct ("Age") [ 62, 14, 16, 656 ]> Db.simple.distinct ("name") [ "abc", "CDE", "def", "Xul", "Jack" ]>
Another piece of reference:
Common commands: http://www.cnblogs.com/cxd4321/archive/2011/06/24/2089051.html
#mongodb # Quick Notes