The basic operations of MongoDB are: Add delete update and read
Start MongoDB Shell: Command line input MONGO (Centos 7)
[[email protected] test] # MONGO MongoDB Shell version:2.6.122017-08-31t17:54:18.621+0800 for are set to 4096KB 2017-08-31t17:54:18.621+0800 [Initandlisten] * * or less 2017-08-31t17:54:18.621+0800 [ Initandlisten] * * http://dochub.mongodb.org/core/readahead
To add a document:
> Db.test.insert ({"key_a":"value_a"" ninserted " : 1 }" > Db.test.insert ({"key_b":"value_b "" ninserted": 1})
To read a document:
Find () can query multiple qualifying documents, FindOne () queries only one,
>Db.test.find () {"_id": ObjectId ("5a12da411c97109757a27d5d"),"key_a":"value_a" }{ "_id": ObjectId ("5a12dab51c97109757a27d5e"),"Key_b":"Value_b"}
>"_id" : ObjectId ("5a12da411c97109757a27d5d" " key_a " " value_a " }
> Db.test.findOne ({"Key_b":"Value_b"}){ "_id": ObjectId ("5a12dab51c97109757a27d5e"),"Key_b":"Value_b" }> Db.test.findOne ({"_id": ObjectId ("5a12da411c97109757a27d5d")}){ "_id": ObjectId ("5a12da411c97109757a27d5d"),"key_a":"value_a"}
To update a document:
> Db.test.insert ({"Key_c":"Value_c"}) Writeresult ({"ninserted": 1 })
> Db.test.findOne ({"Key_c":"Value_c"}){ "_id": ObjectId ("5A12E0A38710E2C2442EDA15"),"Key_c":"Value_c" }
> Db.test.update (Db.test.findOne ({"Key_c":"Value_c"}), {"New_key_c":"New_value_c","Key_c":"Value_c"}) Writeresult ({"nmatched": 1,"nupserted": 0,"nmodified": 1 })
> Db.test.findOne ({"Key_c":"Value_c"}){ "_id": ObjectId ("5A12E0A38710E2C2442EDA15"), "New_key_c":"New_value_c", "Key_c":"Value_c"}
To delete a document:
> db.test.remove ({"key_c":"value_c"" nremoved " : 1 }" > Db.test.findOne ({"key_c":"value_ C"}) null
Basic operation of MongoDB