MongoDB's common operations on collections (tables) and data

Source: Internet
Author: User
Tags bulk insert

First, collection (table of corresponding database) 1, view all the collections in the current library
Show collections
2. Create new collection explicitly
Db.createcollection ("user")
Implicitly-Created
Db. user. Insert ({name: "Zhangsan"})
3. Deleting a Collection
Db. user. Dorpcollection ()

Ii. documents (rows in the corresponding database) 1, new (insert, save, Insertone/insertmany) 1.1, New with Insert method
Db. user. Insert ({name: "Zhangsan", Age:+, Sex: "Boy"})

or define the variables and save the variables first.

Lisi={name: "Lisi", Age:+, Sex: "Girl", Phone: "13999999999"}
Db. user. Insert (Lisi)
1.2. Use the Save method to add
Db. user. Save ({name: "Xiaoli", Age:, Sex: "Girl"})

or define the variables and save the variables first.

Wangwu={name: "Wangwu", Age:+, Sex: "Boy", Email: "XXX@xx. com"}
Db. user. Save (WANGWU)

1.3. Use Insertone (single INSERT, equivalent to insert) and Insertmany (BULK Insert)
Db. User <optional params>-insert  A document, optional parameters are:w, Wtimeout, Jdb. User [objects] <optional params>-Insert Multiple documents, optional parameters Are:w, Wtimeout, J

2. By deleting
Db. user. Dorp ()

3, change

4. Check

MongoDB's common operations on collections (tables) and data

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.