MONGO Common syntax

Source: Internet
Author: User

First, you have to be able to enter the console, not to solve their own.

Basic operation:

Show Users: Show user

Show DBS: Display Database list

Use <db name> switch/CREATE Database

Show Collections: Displays a collection in the current database (similar to a table in a relational database)

Db.help (): Show database Operations Command with a lot of commands

Db.<collections>.help ()

Db<collections>.find ()

Db.<collections>.find ({a:1})

Common statements:

Import and export files to the database

mongoexport-d test-c Students-o Students.dat

mongoexport-d test-c students--csv-f classid,name,age-o Students_csv.dat

Create a database

Use <db name> #创建集合时自动创建use的数据库

Db.clonedatabase ("127.0.0.1") 3 clone the database from the specified machine to the current use database

Db.getname () #显示当前数据库

Db.stats () Displays the current DB status

Db.version ()

Db.getmongo () #当前db链接机器地址

Deleting a database

Db.dropdatabase ()

Modify Database

Db.repairdatabase () #修复数据库

User Management

Db.adduser ("name") #

Db.adduser ("UserName", "pwd123", True) #添加用户, set password, read-only

Db.auth ("UserName", "123123") #数据库认证, Safe mode

Show Users #显示当前所有用户

Db.removeuser ("UserName") #删除所有用户

Db.getpreverror () #查询错误信息

Db.reseterror () #清空错误日志

Create a Collection

Db.createcollection ("Collname", {size:20, Capped:5, max:100});

Delete Collection

Modify a Collection

Query collection data/collection name

Db.getcollection ("account") #查询指定集合

Db.getcollectionnames () #查询当前数据库的所有集合

Db.printcollectionstats () #显示当前db索引状态

Db<collections>.find () #查询指定集合的数据

MONGO Common syntax

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.