且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法使用 MongoDB 超级用户从终端连接到其他数据库

更新时间:2022-11-29 21:49:02

经过身份验证的 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.