Reputation: 11130
I set up a user in my "stocks" database intending this user to be able to fully administer the collections and indexes in the stocks database.
dmReplSet:PRIMARY> use stocks
switched to db stocks
dmReplSet:PRIMARY> db.addUser( { user : "stocks", pwd : "b0nd5", roles : [ "dbOwner", "backup", "restore" ] } );
dmReplSet:PRIMARY> db.system.users.find()
{ "_id" : ObjectId("537bb7d963095ee3392c552e"), "user" : "stocks", "pwd" : "24efdd0922a7c949e1e9c355e7d7648c", "roles" : [ "dbOwner", "backup", "restore" ] }
If I understand MongoDB's "built in roles" correctly (http://docs.mongodb.org/manual/reference/built-in-roles/) setting this guy as "dbOwner" should have granted me these priviledges on the "stocks" database.
Mongo Shelling in as this user, however, shows that I can't do anything. I can't find, I can't insert, all I can do is shell in. Arghhhh. Where did I go wrong. Does the "dbOwner" role not really grant me all the access I need on the database I put my user into?
bobk-mbp:~ bobk$ mongo -u stocks -p 'b0nd5' localhost/stocks
MongoDB shell version: 2.4.6
connecting to: localhost/stocks
> db
stocks
> db.bob.find()
error: { "$err" : "not authorized for query on stocks.bob", "code" : 16550 }
>
I am operating a Mongo 2.4.6 replica set.
Upvotes: 1
Views: 3070
Reputation: 11130
The "dbOwner" role doesn't exist at Mongo 2.4.6. Adding the component roles of "readWrite", "dbAdmin", "userAdmin" to the roles fixes the issue.
dmReplSet:PRIMARY> use stocks
switched to db stocks
dmReplSet:PRIMARY> db.addUser( {
user : "stocks",
pwd : "b0nd5",
roles : [ "readWrite", "dbAdmin", "userAdmin", "backup", "restore" ]
} );
dmReplSet:PRIMARY> db.system.users.find().pretty()
{
"_id" : ObjectId("537bc4d563095ee3392c5531"),
"user" : "stocks",
"pwd" : "24efdd0922a7c949e1e9c355e7d7648c",
"roles" : [
"readWrite",
"dbAdmin",
"userAdmin",
"backup",
"restore"
]
}
Upvotes: 1