0
votes

New to MongoDB, trying to figure out how permissions work.

My PHP code connects to Mongo just fine:

$mongo = new MongoClient('mongodb://admin:password@localhost');
return $mongo->selectDB('admin');

I can also do this from shell:

# mongo -u admin -p password admin
MongoDB shell version: 3.0.5
connecting to: admin

However, an attempt to connect to Mongo from other remote host using the same credentials (Windows, in this case) results in:

Failed to authenticate admin@admin with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document

I am trying to configure Robomongo admin tool to manage MongoDB instance.

Obviously, I've allowed connections to Mongo server by updating IP binding directive.

It looks like "admin" user is not allowed to connect from a host other than localhost - MySQL has exactly the same parameter.

The question: how do I allow admin user to connect from outside the box?

Thanks!

1

1 Answers

0
votes

So here's what I had to do.

  1. Drop all existing admin users.

  2. To configure authentication mechanism, start mongodb WITHOUT authorization: "enabled". Then:

mongo admin

From mongo shell:

var schema = db.system.version.findOne({"_id" : "authSchema"})
schema.currentVersion = 3
db.system.version.save(schema)
db.createUser(
{
  user: "admin",
  pwd: "password",
  roles: [ "root" ]
}

)

and restart with authorization: "enabled".