[Mongo] Simple Operation command

Source: Internet
Author: User

1. Connect to the server:

Mongo

2. Connect to the database

Use dbname

3. Querying the names of all collections

Db.getcollectionnames ()

4. Querying data for a collection

Db.collection.find ()

Db.collection.find ({columnname: "value"})//accept only one parameter

5. Inserting data in a collection

Insert a single column of data: Db.collection.insert ({columnname: "value"})

Insert a two-column data: Db.collection.insert ({columnname1: "value1", columnname2: "value2"})

Insert multiple records: for (i=1;i<100;i++) Db.collection.insert ({columnname:i})

6. Updating Data

Db.collection.update ({column1:1},{column1:999})

Db.collection.update ({column1:100},{$set: {column2:99}})//Set Column2 for record Column1 to 100 to 99

7. Delete

Delete Table: Db.collection.drop

Delete database: Db.dropdatabase ()

Delete Record: Db.collection.remove ({column:100})

[Mongo] Simple Operation command

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.