I am running mongo 2.6.1 on windows, I wanted to crate a user and then grant roles to the user for different dbs.
mongo admin -u superuser -p 12345678
db.createUser({'user':'test4', 'pwd':'test4', roles:[{'role':'read', 'db':'db1'}]});
After this I can log in to db1 when I run
mongo db1 -u test4 -p test 4
After this I logged out and ran the following
mongo admin -u superuser -p 12345678
db.grantRolesToUser( "test4", [ { role: "readWrite", db: "db2" } ])
Now when I run the following
mongo db2 -u test4 -p test 4
I get the error
MongoDB shell version: 2.6.1
connecting to: db1
2014-12-11T13:35:29.891-0500 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210
exception: login failed
in Admin, show users shows that test4 has expected access to the dbs.
Can someone please explain what I am missing? How do I fix this?
test4 is a user created in the admin database, so to authenticate as that user you need to authenticate to the admin database. Try using the --authenticationDatabase option:
Thanks for the response William, the discrepancy I have is I can connect to db1 directly as
mongo db2 -u test4 -p test4 --authenticationDatabase admin
Thanks for the response William, the discrepancy I have is I can connect to db1 directly as
mongo db1 -u test4 -p test4 even though that is also created in admin, right?
But when I do the same with granRoles it does not work, which I fail to understand.
Can you please shed some light on it?
댓글 없음:
댓글 쓰기