4.MongoDB command Line
①mongodb Command-line Introduction
The MONGO command line is the JavaScript interface for the MONGODB database. This command line can be used to make database pruning, performance management and other operations.
The MONGO command line is a component of MongoDB. When you start MongoDB, you can use the command line to connect to MongoDB.
② Start MongoDB command line
Before starting the MongoDB command line, you need to make sure that MongoDB is started.
Enter MongoDB installation bin
directory.
Windows
Performmongo.exe
Linux
./mongo
MongoDB Default IP and port
MongoDB Default binding IP is 127.0.0.1, Port is 27017. If the MONGO default configuration is not modified. The Execute MONGO command will connect 127.0.0.1:27017.
③mongo Show All databases
Show DBS;
④mongo using or creating a database
If the specified database does not exist, a database is created.
Use dashdan_com
⑤mongo Displays the currently used database
Db
⑥mongo Inserting data
Use Dashdan_comdb.myCollection.insertOne ({x:1});
Description
DB is the index of the database currently in use, so don't write the database name here. db
The name of the mycollection dataset. This can be customized.
⑦mongo Finding data
Db.myCollection.find ();
If the name of the dataset has spaces or special characters can be obtained by db.getcollection ().
Cases:
Db.getcollection ("mycollection"). Find ();
The MONGO command line receives a maximum of 4,095 characters per line, and the MONGO command shortens it by exceeding this limit.
⑧mongo command output result formatting
Db.myCollection.find (). Pretty ()
You can also set the MONGO command to display the results in the following ways:
⑨mongo command Multi-line mode
On the MONGO command line, if the{
,[
,(
End, the next line is...
Start until you meet the symbol that corresponds to it}
,]
,)
.
> if (x > 0) {... count++; .... print (x); ...}
You can also end this statement by entering two blank lines in a row.
> if (x > 0......>
⑩mongo Command Line exit
Input quit()
, or press Ctrl-C
.
Reference articles
Official articles
The latest content will be updated at the source station. Reprint please keep the original link: http://dashidan.com/article/mongodb/index.html
This article is from the "13402341" blog, please be sure to keep this source http://13412341.blog.51cto.com/13402341/1976405
4.MongoDB command Line