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

查看:62
本文介绍了无法使用 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/.这意味着您必须先登录admin",然后才能使用数据库".

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

或者,我怀疑但尚未测试您是否可以将超级用户放入test"数据库而不是admin",默认情况下,shell 将您置于该数据库中.这将使您无需在 mongo 命令行中使用admin",但现在您已将用户维护在不同的位置.岩石.硬地.

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天全站免登陆