MongoDB Command (1)

Source: Internet
Author: User
Tags bulk insert delete key

After successfully starting the MongoDB service, open a command-line window to enter MONGO, you can do some operations of the database.

Enter help to see the basic Operations Command:

Show DBS: Display Database list
Show Collections: Displays a collection in the current database (similar to a table in a relational database)
Show Users: Show user

Use <db name>: Toggle/Create Current database

Db.foo.insert () Inserting a piece of data

Db.foo.find () Find out all the data

Db.foo.findOne () Find a piece of data

Db.foo.update () Update data

Db.foo.remove () Delete all data for the current table

Db.foo.drop () Delete current table, delete fast

Db.foo.batchInsert () BULK INSERT

Db.foo.upsert () If no eligible document updates are found, create a new document based on this condition and update the document, and update if the document is found

$set Specify a field value to create if the field does not exist

Db.foo.update ({},{"$set": {"name": "Lucy"}}) only update the first record found

$unset Delete key

Db.foo.update ({},{"$unset": {"name": 1}}) remove the name key and update only the first entry that found the record

$inc increase or decrease the value of an existing key, if the key does not exist, create one, increase the number type only, modify in-place

Db.foo.update ({},{"$inc": {"score": 1}}) score increased by 1

MongoDB Command (1)

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.