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