MongoDB Basic Operations

Source: Internet
Author: User

Mongdodb instance-"Database-" collection-"Document-" field (Key/value pair)


Bin execution./mongod Startup & Background Boot

./mongo into MongoDB shell Many of these commands resemble MySQL show DBS (view database)

Start Error:/data/db/mongod.lock is not empty.

Kill Mongod, delete mongod.lock, this file resembles record MongoDB still start cache file


Create a database

Use namedb Create a database named Namedb and insert the data before you can view it via show DBS


Deleting a database

Use Namedb first enters the database Db.dropdatabase () and then deletes the database (the test database is deleted by default if you do not enter the appropriate database)


Create a collection in the database

Db.createcollection ("CollectionName")


To delete a specified collection in a database

Db.collectionName.drop ()


Inserting a document into the collection

Db.collectionName.insert ({"Namedockey": "Namedocvalue"}) similar to the Save method


Querying collection data

Db.collectionName.find () query. Pretty () query and format display Db.collectionName.find ({"Key": "Value"}); Querying the specified document


Modifying a document

Db.collectionName.update ({"Key": "Value"},{"NewKey": "Value"},{upsert:true}) Upsert=true if not present, Insert Db.collectionName.update ({"Key": "Value"},{$set: {"Oldkey": "NewValue"}}) to modify the specified property


Delete a document

Db.collectionName.remove ({}) deletes all documents in the collection without deleting the collection db.collectionName.list.remove ({"Key": "Value"}) deletes the specified document


This article is from the "Stuffed Pig" blog, please be sure to keep this source http://zuohao1990.blog.51cto.com/6057850/1883265

MongoDB Basic Operations

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.