简体   繁体   English

Mongo用户权限,可读写任何数据库

[英]Mongo user privilege to read and write to any database

Mongo newb here. Mongo newb在这里。 I have a mongo installation with four databases and would like to create a user that can read and write to all the databases. 我有一个包含四个数据库的mongo安装,并且想创建一个可以读写所有数据库的用户。 I tried: 我试过了:

use admin;
db.addUser({user: "foo" , pwd: "bar", roles: [  "readWriteAnyDatabase" ]})

but when I try to do 但是当我尝试去做

mongo someotherdb -u foo -p

and authenticate with the correct password it gives me an authentication error. 并使用正确的密码进行身份验证,这会给我一个身份验证错误。

I also tried manually adding the users to the other databases by doing this 我还尝试通过这样做将用户手动添加到其他数据库

use someotherdb
db.addUser({user: "foo", roles: ['readWrite'], userSource: "admin"});

and still no dice trying to log in via the mongo shell or using the auth command in the target db. 而且仍然没有骰子尝试通过mongo shell或在目标数据库中使用auth命令登录。

Am I doing something wrong? 难道我做错了什么? How do you go about making a user who can globally read and write to any db? 如何使用户可以全局读写任何数据库? Do you have to add said user to each db's system.users collection or is that not necessary if they have the "readWriteAnyDatabase" role? 您是否必须将所述用户添加到每个数据库的system.users集合中,或者如果它们具有“ readWriteAnyDatabase”角色,则不必这样做吗?

I'm using mongo 2.4 on ubuntu. 我在ubuntu上使用mongo 2.4。

So, I've finally figured this out. 所以,我终于弄清楚了。 Note, this fix only works for Mongo 2.4. 请注意,此修复程序仅适用于Mongo 2.4。

In 2.4 you can specify a database to authenticate yourself with in the connection string or on the command line 在2.4中,您可以在连接字符串或命令行中指定一个数据库来进行身份验证

So to create the initial user 所以要创建初始用户

use admin
db.createUser({user: "foo" , pwd: "bar", roles: [  "userAdminAnyDatabase","readWriteAnyDatabase" ]})

and to authenticate use 并验证使用

mongo -u foo --authenticationDatabase admin -p

Now you should be able to do whatever you want to any DB 现在,您应该可以对任何数据库执行任何操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM