MongoDB remote connection via RoboMongo

16,840

Solution 1

Does Mongodb have default user name or password?

There are no default users created by MongoDB, however if you have just enabled authentication and haven't created your first user yet (which should be a user administrator), then you have to connect via localhost to set up up the initial user. There is a localhost exception enabled by default to specifically to allow creation of the first user with auth enabled. Remote connections will not be able to authenticate without valid user credentials.

After you have created the required user(s), you should then be able to login remotely with those credentials using Robomongo or another interface like the mongo shell or your mongoskin app.

If you don't want to use the localhost exception an alternative approach would be to start your MongoDB server with auth disabled, add the required users remotely, and then restart the server with auth enabled.

Solution 2

All you need is in the docs: http://docs.mongodb.org/manual/tutorial/enable-authentication/

Create admin user (role):

use admin
db.createUser(
  {
    user: "siteUserAdmin",
    pwd: "password",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
)

Add normal users (read write role):

use reporting
db.createUser(
    {
      user: "reportsUser",
      pwd: "12345678",
      roles: [
         { role: "read", db: "reporting" },
         { role: "read", db: "products" },
         { role: "read", db: "sales" },
         { role: "readWrite", db: "accounts" }
      ]
    }
)

To add the admin, you probably need to start mongo using auth=false, add adminuser, and re-enable auth=true.

To view roles: db.getRoles()

Share:
16,840
tubu13
Author by

tubu13

Updated on August 19, 2022

Comments

  • tubu13
    tubu13 over 1 year

    I'm trying to connect to my Mongodb server via Robomongo.

    I have changed the Bind_ip to 0.0.0.0 at the server mongod.conf I have also set the auth=true field.

    Now when I'm trying to log in from RoboMongo I'm getting auth fail error.

    To be honest i have no idea what is the user name or password (I didn't set any user after installing Mongo, and i prefer not to because I'm using nodeJs to query the db and when i try to log in I'm getting auth fail as well [thats with mongoskin])

    Does Mongodb have default user name or password? or what else can I do?

  • Mike S
    Mike S over 8 years
    Sometimes the docs don't get you across the finish line. I came here because I had an authentication issue much the same as the OP. As a matter of fact, I could authenticate from my remote host using the mongo shell- but Robomongo still wouldn't work. That was when I discovered this: stackoverflow.com/questions/29325011/… . Note that I have Robomongo 0.8.5 and Mongo 3.0.3, so that combination will not work. I need to update Robomongo.
  • Daniel W.
    Daniel W. about 7 years
    @MikeS I wasn't aware of this. I think my answer together with your comment will help many others with the same problem.