MongoDB 无权查询 admin.system.users

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22067612/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 13:36:50  来源:igfitidea点击:

MongoDB not authorized for query admin.system.users

mongodbauthenticationnosql

提问by AnonymousCoder

I am bit new to MongoDb and I am using MongoDb v.2.4.Here the problem is that when I run the mongod with --auth parameter, even after authenticating I am not able to perform simple operations such as "show users". But works fine if I run mongod without --auth parameter.

我对 MongoDb 有点陌生,我正在使用 MongoDb v.2.4。这里的问题是,当我使用 --auth 参数运行 mongod 时,即使经过身份验证,我也无法执行诸如“显示用户”之类的简单操作。但是如果我在没有 --auth 参数的情况下运行 mongod 就可以了。

> use admin
switched to db admin
> db.auth("dbadmin","mypassword")
1
> show users
**Thu Feb 27 16:50:17.695 error: { "$err" : "not authorized for query on admin.sys
tem.users", "code" : 16550 } at src/mongo/shell/query.js:128**

回答by sivi

> use admin
switched to db admin
> db.grantRolesToUser("your_admin_name" ,[ "root"])

This command will give you all privileges on any db as admin.

此命令将以管理员身份授予您对任何数据库的所有权限。

回答by Ivan.Srb

Firstly you should to run mongod on localhost without --authand create user with necessary rolesthat you needed. In your case you should add userAdminAnyDatabaseor userAdminrole. Than you could run mongod with --authand authenticate by this user for have remote access to system.userscollections.
You could read about it here.

首先,您应该在 localhost 上运行 mongod--auth并创建具有您需要的必要角色的用户。在您的情况下,您应该添加userAdminAnyDatabaseuserAdmin角色。您可以使用--auth该用户运行 mongod并通过该用户进行身份验证以远程访问system.users集合。
你可以在这里阅读它。

回答by doom

I think your admin user has not been configured as mongo says.

我认为你的管理员用户没有像 mongo 所说的那样配置。

I have just answer a question in another thread with explanation step by step : Not authorized for query on admin.system.namespaces on mongodb

我刚刚在另一个线程中回答了一个问题,并逐步进行了解释: 未授权在 mongodb 上查询 admin.system.namespaces

try it.

尝试一下。

回答by Day Davis Waterbury

Not for the OP, but for those of you landing here on an internet search for

不是为了 OP,而是为了那些在互联网上搜索到的人

Failed: error counting admin.system.users: not authorized on admin to execute command { count: "system.users", query: {}, $db: "admin" }

The answer, most likely, is that you need to specify the database name in the connection string. For example, in my case, I was doing a mongorestore, like so

答案很可能是您需要在连接字符串中指定数据库名称。例如,就我而言,我正在做一个mongorestore,就像这样

mongorestore --uri=mongodb+srv://[username]:[password]@[mongo-server] --dir=[backup-file]

And what I needed to do was

我需要做的是

mongorestore --uri=mongodb+srv://[username]:[password]@[mongo-server]/[database-name] --dir=[backup-file]

The same thing would apply to a mongodump. The point is that it tries to connect to the adminDB by default, and that might not be what you're trying to do.

同样的事情也适用于mongodump. 关键是它admin默认尝试连接到数据库,而这可能不是您想要做的。