Admin user cannot login to another database on mongodb

Mongo user can login to admin database. But cannot enter other databases.

I have given the user the following privileges.

Privilege command:

db.createUser( { user: "root", pwd: "password", roles: [ "readWriteAnyDatabase", "userAdminAnyDatabase", "dbAdminAnyDatabase", "clusterAdmin" ]} )

      

When accessing another form of Mongo Shell DB I got below error

Command line:

C:\mongodb\bin>mongo.exe database-name -u root -p

2014-12-01T12:00:05.806+0000 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210
exception: login failed

      

So how can I grant DB access with the same user? Can anyone help on this.

+3


source to share


1 answer


You need to authenticate to the database where the user exists. The easiest way to do this with a shell is to use--authenticationDatabase



mongo.exe database-name -u root -p ***** --authenticationDatabase admin

      

+3


source







All Articles