Cannot authenticate after grantRolesToUser

79 views
Skip to first unread message

manushka

unread,
Dec 11, 2014, 1:51:24 PM12/11/14
to mongod...@googlegroups.com
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.


These are the commands I ran

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?

Regards







Will Berkeley

unread,
Dec 12, 2014, 10:46:43 AM12/12/14
to mongod...@googlegroups.com
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:

mongo db2 -u test4 -p test4 --authenticationDatabase admin

-Will

manushka

unread,
Dec 15, 2014, 9:54:56 AM12/15/14
to mongod...@googlegroups.com
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?
Regards
- Anu
Reply all
Reply to author
Forward
0 new messages