Blog Post

MongoDB – Local and Remote Connections in Mongo Shell

,

To Install and Getting started with MongoDB refer the below links

How to access Mongo instance

  • Open a terminal session or command window.
  • For a local connection to mongod, at the operating system prompt, enter the following command to start the mongo executable:

[mongo@MongoServer1 ~]$ mongo

logon Screen 1

The shell automatically attempts to connect to a MongoDB server on startup, so make sure you start mongod before starting the shell.

  • For remote connections, we can connect your shell to any MongoDB instance that your machine can reach.
  • To connect to amongod on a different machine or port, specify the hostname, port, and database when starting the shell
  • At the operating system prompt, enter the following command to start the mongo executable:

[mongo@MongoServer2 ~]$ mongo MongoServer1:27017/foobar

logon Screen 2

  • We can also start the mongo shell without connecting to any mongod server

[mongo@MongoServer1 ~]$ mongo –nodb

logon Screen 3

We can connect to the mongod server at a later point in time, by running :

>conn = new Mongo(“some-host:30000”)

>db = conn.getDB(“test”)

logon Screen 4

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating