MongoDB Notes (i)

Source: Internet
Author: User
Tags modifier

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.