简体   繁体   中英

Authentication error while connecting to MongoDB from remote host

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!

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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM