1, the MONGODB database is dynamically generated by using the use database name to specify the database to use, and if the database does not exist, automatically generates a2. Insert a document: Db.foo.insert ({"Name": "Zhang San"}) If the _id column does not exist, then the _id column will be generated automatically at the time of insertion3. Delete Db.blogs.remove ({"title": "Blog")}); Delete the "blog" Data in the Blogs collection "Delete is permanent and cannot be undone or restored"4, $set can be used to modify the value of a key, if the key does not exist to create it "Db.users.update ({" Name ":" Joe "},{" $set ": {" Favorite book ":" War and Peace "}}); "5, $set can also be used to modify the data type of the key, such as changing the value of the key to an array "db.users.update ({"Name": "Joe"},{"$set": {"Favorite book": ["Cat's Cradle", "Foundation Trilogy", "Ender1s Game"]}}) "6, you can use $unset to remove the key "Db.users.update ({" Name ":" Joe "},{" $unset ": {" Favorite book ": 1})) "7, $inc modifier is used to increase the value of the existing key (only for integers, long integers or double-precision floating-point numbers), or to create a key when the key does not exist "Db.games.update ({" Game ":" Pinball "},{" $inc ": {" score ": 50}}) "7.1, give score plus 1000 "db.games.update ({" Game ":" Pinball "},{" $inc ": {" score ": 1000}}) "8. Array modifier: [$pop and $push can only be used to value the key of the array type] If the specified key exists, "$push"adds an element to the end of an existing array, and creates a new array if it is not.8.1, Db.games.update ({"Game": "Pinball"},{$push: {"comments": {"name": "Joe", "Emai": "[email protected]", "Content": " Nice post. "}}})
MongoDB Notes (i)