The mongo shell is a component of the MongoDB distributions.
Once we have installed and have started MongoDB server (mongod), we can connect the mongo shell to our running MongoDB instance.
Starting The Mongo Shell:-
Basic Syntax of mongo command is as follows
Options are optional but options are useful in some cases, let’s view some key options.
|--port||Specifies the port where the mongod or mongos instance is listening. If --port is not specified, mongo attempts to connect to port 27017.|
|-- host||Specifies the name of the host machine where the mongod or mongos is running. If this is not specified, mongo attempts to connect to a MongoDB process running on the localhost.|
|<dbname>||Specifies the “database name” of the database to connect.
ex:- mongo workdb
|<host:port>||Specifies the connection with host and port details,
direct usage of –host, --port
ex:- mongo 192.168.0.7:27017
Some Example ways to Start the mongo shell
Open the terminal and go to MongoDB installation directory.