无法将MongoDB超级用户从终端连接到其他数据库 [英] Cannot connect with the MongoDB superuser to the other databases from the terminal

查看:509
本文介绍了无法将MongoDB超级用户从终端连接到其他数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在管理数据库中定义了superuser:

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?

推荐答案

经过身份验证的mongo是一种皇家痛处.即使您的超级用户本质上是[[userAdminAnyDatabase","dbAdminAnyDatabase","clusterAdmin","readWriteAnyDatabase"]的全能者,但如果您按照 http://docs.mongodb.org/manual/tutorial/enable-authentication/.这意味着您必须先登录管理员",然后才能随意使用使用数据库".

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

或者,我怀疑但尚未进行测试,您可以将超级用户放入测试"数据库而不是"admin"数据库中,而默认情况下,shell会将您置于该数据库中.这样一来,您就可以将"admin"保留在mongo命令行之外,但是现在您已将用户维护在不同的位置.岩石.困难的地方.

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.

这篇关于无法将MongoDB超级用户从终端连接到其他数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆