Cannot connect with the MongoDB superuser to the other databases from the terminal

僤鯓⒐⒋嵵緔 提交于 2019-12-06 06:08:39

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/20543505/cannot-connect-with-the-mongodb-superuser-to-the-other-databases-from-the-termin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!