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

Advertisements

About Prashanth Jayaram

I’m a Database technologist having 11+ years of rich, hands-on experience on Database technologies. I am Microsoft Certified Professional and backed with a Degree in Master of Computer Application. My expertise lies in T-SQL programming, Replication and PowerShell You can connect me via https://social.technet.microsoft.com/profile/prashanth jayaram/ http://www.sqlshack.com/author/prashanth/ https://www.tumblr.com/blog/prashantjayaram http://www.sqlservercentral.com/blogs/powersql-by-prashanth-jayaram/ http://www.toadworld.com/members/prashanthjayaram/ My Articles are published in following sites http://www.ssas-info.com/analysis-services-articles/ http://db-pub.com/ http://www.sswug.org/sswugresearch/community/
This entry was posted in MongoDB and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s