https://docs.mongodb.com/getting-started/shell/client/

The mongo shell is an interactive JavaScript interface to MongoDB and is a component of the MongoDB package.

You can use the mongo shell to query and update data as well as perform administrative operations.

 

Start mongo

Once you have installed and have started MongoDB, connect the mongo shell to your running MongoDB instance.

Ensure that MongoDB is running before attempting to launch the mongo shell.

On the same system where the MongoDB is running, open a terminal window (or a command prompt for Windows) and run the mongo shell with the following command:

mongo

On Windows systems, add .exe as follows:

mongo.exe

You may need to specify the path as appropriate.   //如果配置到环境变量的话,可以直接mongo

 

When you run mongo without any arguments, the mongo shell will attempt to connect to the MongoDB instance running on the localhost interface on port 27017.

To specify a different host or port number, as well as other options, see mongo Shell Reference Page.

 

mongo --host localhost --port 27017

mongo --host 192.168.1.18 --port 27017

 

C:\Users\Administrator>mongo --host 192.168.1.63 --port 10001
MongoDB shell version v3.4.2
connecting to: mongodb://192.168.1.63:10001/
MongoDB server version: 3.4.2
Server has startup warnings:
2017-03-02T17:36:14.784+0800 I CONTROL [initandlisten]
2017-03-02T17:36:14.784+0800 I CONTROL [initandlisten] ** WARNING: Access contr
ol is not enabled for the database.
2017-03-02T17:36:14.785+0800 I CONTROL [initandlisten] ** Read and wri
te access to data and configuration is unrestricted.
2017-03-02T17:36:14.785+0800 I CONTROL [initandlisten]
2017-03-02T17:36:14.785+0800 I CONTROL [initandlisten] Hotfix KB2731284 or late
r update is not installed, will zero-out data files.
2017-03-02T17:36:14.785+0800 I CONTROL [initandlisten]

 

Help in mongo Shell

Type help in the mongo shell for a list of available commands and their descriptions:

help

The mongo shell also provides <tab> key completion as well as keyboard shortcuts similar to those found in the bash shell or in Emacs.

For example, you can use the <up-arrow> and the <down-arrow> to retrieve operations from its history.

 

 

Additional Information

See the following documents in the MongoDB Manual for more information on the mongo shell.