MongoDB Common Operations--command line

Source: Internet
Author: User
Tags mongodb

Increase:

Db:

Use db_name//If there is a switch

Tabale:

There is no direct command to automatically generate when inserting a document

File

Db.table_name.insert ({' Test ': ' OK '})

Field:

Db.table_name.update ({' Test ': {$exists: true}},{$set: {' test2 ': ' Yes '}},{multi:true})//Insert ' test2 ' field into all documents containing ' test ' field

Db.table_name.update ({' Test ': {$exists: true}},{$set: {' test2 ': ' Yes '}})//Find the first document containing the ' Test ' field insert ' test2 ' field

Db.table_name.update ({' Test ': ' OK '},{$set: {' test2 ': ' Yes '}},{multi:true})//Insert ' test2 ' field into all documents containing ' test ': ' OK ' key-value pairs

By deleting:

Db:

Db.dropdatabase ()//delete current database

Table

Db.table_name.drop ()

File

Db.table_name.remove ({' Test ': {$exists: True}},{justone:true})//delete the first one found

Db.table_name.remove ({' Test ': {$exists: true}})//delete all

Field:

Db.table_name.update ({//Search condition},{$unset: {' Test ': '}},{multi:true} ')//delete all fields that meet {condition}

Check:

Db:

Show DBS

Table

Show tables

File

Db.table_name.find ({//Search condition}). Pretty ()//pretty () formatted display

Field:

No

Change:

Db:

Use Db_name

Table

No

File

Db.table_name.update ({' Test ': {$exists: true}},{' test2 ': ' Yes '},{multi:true})//Replace all document contents containing test with {' test2 ': ' Yes '}// The ' _id ' value does not change

Field:

Db.table_name.update ({' Test ': {$exists: true}},{$set: {' Test ': ' Yes '}},{multi:true})//To the ' Test ' field value for all documents containing ' test ' field ' Yes '

    

MongoDB Common Operations--command line

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.