I have defined a superuser
in my admin database:
$ mongo admin -u superuser -p 1234
MongoDB shell version: 2.4.6
connecting to: admin
> db.system.users.findOne()
{
"_id" : ObjectId("52a9a8bd2db854b07d3960f1"),
"user" : "superuser",
"pwd" : "8c246ca972a74c8049b79771df9b718b",
"roles" : [
"userAdminAnyDatabase",
"dbAdminAnyDatabase",
"clusterAdmin",
"readWriteAnyDatabase"
]
}
But now I cannot connect to another database with this user:
$ mongo mono -u superuser -p 1234
MongoDB shell version: 2.4.6
connecting to: mono
Thu Dec 12 13:22:42.100 Error: 18 { code: 18, ok: 0.0, errmsg: "auth fails" } at src/mongo/shell/db.js:228
exception: login failed
Is this a know feature/limitation or am I doing something wrong?
Authenticated mongo is a royal pain-in-the-butt. Even though your superuser is basically omnipotent by nature of [ "userAdminAnyDatabase", "dbAdminAnyDatabase", "clusterAdmin", "readWriteAnyDatabase"], his system.user account is still based in the "admin" database if you set it up as per http://docs.mongodb.org/manual/tutorial/enable-authentication/. This means you have to log in to "admin" first, then you can "use database" your way around.
$ mongo mono -u superuser -p 1234 admin
MongoDB shell version: 2.4.6
connecting to: admin
myReplSet:PRIMARY> use mono
Alternatively, I suspect but haven't tested that you could put your superuser into the "test" database rather than "admin" which is where the shell lands you by default. That would let you leave the "admin" off the mongo command line, but now you've got your users maintained in different places. Rock. Hard Place.