Wednesday 15 July 2015

Connect To Mongo DB Instance


In my previous blog I have created the instance. If you are not having any instance running then please create one. You can follow my previous blogs for that.

Assuming, you have a server running without authentication mode. So in that case it becomes very easy, we don’t need any password or any user name. There are many ways we can connect to the server.
  •     Using cmd prompt
  •     Using mongo.exe, which is client tool for mongo DB.
  •     Using third party tool like mongochef, Robomongo

Using cmd prompt:
You open cmd prompt and change the directory to bin folder of mongo DB and then type below commands.

Default connection and without authentication:
{mongo} --> Then press enter.



But if you are connecting to a secure server then you should use below command:
{mongo localhost:27017/admin –u sa –p }, Then press enter.
  • –u sa –p are required only when you are connecting server instance in authenticated mode.
  • localhost:27017/admin --> This is the location and port where server is hosted.

Using mongo.exe:
Just double click on this executable to open in default mode.

But if you are connecting a particular server, then use command
{db=connect(“localhost:27017/admin”);}

This will connect to the database and if there is authentication in the server then you should use authentication command   soon after the connections are established as below
{db=connect(“localhost:27017/admin”);}
{db.auth (“user”, “Password”);}




References:

1 comment:

  1. Nice guidance Shekhar.

    Please continue writing on creating databases, tables (collections), querying, Crud Operations.... Also a post on comparing basic SQL syntax with MongoDB syntax this really would help for those who already have RDBMS background.

    Can you add little bit about waht is NoSQL DB, compare features with RDBMS in the first article of this series.

    ReplyDelete