为MongoDB用户提供对其他数据库的访问 [英] Providing a MongoDB user with access to additional databases
问题描述
我在admin数据库上创建了一个在admin数据库上具有角色userAdminAnyDatabase的用户。
当尝试列出数据库(使用 show databases 命令)时,访问级别工作正常,但在任何时候运行 show collections 命令时会抛出以下错误数据库而不是管理。这是错误
I have created a user on the admin database that has the role "userAdminAnyDatabase" on the admin database. The access level works fine while trying to list the databases (using the show databases command) but throws the following error when I run the show collections command on any database other than admin. Here is the error
错误:listCollections失败:{
ok:0,
errmsg: 未授权on xxxx执行命令{listCollections:1.0,filter:{}},
code:13,
codeName:未授权
Error: listCollections failed: { "ok" : 0, "errmsg" : "not authorized on xxxx to execute command { listCollections: 1.0, filter: {} }", "code" : 13, "codeName" : "Unauthorized"
我尝试使用以下命令更新用户以提供访问:
I tried to update the user to provide access using the following command:
db.updateUser(xyz,{pwd:abcd,roles:[{role:userAdminAnyDatabase,db:admin},{role:userAdminAnyDatabase,db:employee}]}) p>
db.updateUser("xyz",{pwd:"abcd",roles:[{role:"userAdminAnyDatabase",db:"admin"},{role:"userAdminAnyDatabase",db:"employee"}]})
我收到以下错误:
错误:无法添加用户:没有角色名为userAdminAnyDatabase @ employees
Error: couldn't add user: No role named userAdminAnyDatabase@employees
我必须将角色专门添加到每个数据库工作?
Do I have to add the roles specifically into each database for this to work?
推荐答案
使用 userAdminAnyDatabase
但是此角色不能从应用程序数据库/集合读取/写入数据。
With userAdminAnyDatabase
role you can manage user; but this role cannot read/write data from application databases/collections.
对于读取/读写操作,可以使用 c $ c> /
readWrite
角色或您可以添加 readAnyDatabase
/ readWriteAnyDatabase
角色给管理员用户。
For read/readWrite operation either create users on database with read
/readWrite
role or you can add readAnyDatabase
/readWriteAnyDatabase
role to the admin user.
这篇关于为MongoDB用户提供对其他数据库的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!