Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB authentication access to the database local

I just upgraded my MongoDB instance from 2.4.x to the latest 2.6. And I configured Mongo to enable the authentication by updating this property:

auth = true

Then, I created users in each collection with specific roles. And it's working well.

But I have RockMongo connected to this instance, and I have this error:

Failed to connect to: XXX:YYY: Authentication failed on database 'local' with username 'ZZZZ': auth failed

I tried to connect to the 'local' database, and to create a new user like that:

use local
db.createUser(
  {
    user: "XXX",
    pwd: "YYY",
    roles: [ { role: "readWrite", db: "local" }, { role: "userAdminAnyDatabase", db: "local" } ]
  }
)

But, I get an error:

2015-02-20T15:49:55.892+0000 Error: couldn't add user: Cannot create users in the local database at src/mongo/shell/db.js:1004

Any idea, why ?

Thanks for your help.

like image 667
Ben Chevallereau Avatar asked Feb 20 '15 15:02

Ben Chevallereau


1 Answers

you cannot create users in the local database http://docs.mongodb.org/manual/reference/method/db.createUser/#local-database

Instead, you can create your user in the admin database who can readWrite in the local db:

use admin
db.createUser(
   {
      user: "XXX",
      pwd: "YYY",
      roles: [ { role: "readWrite", db: "local" } ]
   }
)

When logging in as user XXX, be sure to specify the --authenticationDatabase admin

like image 78
Kay Avatar answered Oct 19 '22 22:10

Kay