MongoDB Learning Notes ~ Use of client command line

Source: Internet
Author: User

When we download the installation package from the MongoDB website, it will accompany with a series of tools, the server program Mongod is familiar to us, the client MONGO and performance detection mongostat we may not have used, Today is mainly about the use of MONGO this client command-line tool.

Test environment: Server: Linux version of Mongod 2.6.9

Client: Window version of MONGO 2.6.9

Here are some common commands

1 Create a new link

var x=New Mongo ("192.168.2.4:27017")

2 Show all databases

Show DBS

3 Specify the database that you want to use now

var db=x.getdb ("background")

4 Get the name of the current database

Db.getname ()

5 getting all the collections of the database

Db.getcollectionnames ()

6 getting the details of the collection in the database

Db.getcollectioninfos ()

7 getting the specified collection

Db.getcollection ("background")

8 get the number of elements in the collection

Db.getcollection ("background"). Count ()

9 Getting server-related information

Db.hostinfo ()

10 Getting connection information for the current MONGO server

Db.getmongo ()

11 adding an index to the fields for sorting and querying

Understand the database of friends should not be unfamiliar with the index, when the amount of data compared to an hour, it does not play any role, when the data volume is larger than 500W, your field needs to be indexed, the performance improvement is quite obvious, if you do not add, then you wait for the Epiphyllum to open it, hehe!

Db.dbName.ensureIndex ({FieldName:1})//1 is ascending,-1 is descending db.dbName.getIndexes ()

MongoDB Learning Notes ~ Use of client 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.