MongoDB未授权查询admin.system.users

时间:2014-02-27 11:48:10

标签: mongodb authentication nosql

我对MongoDb有点新,我使用的是MongoDb v.2.4。问题在于,当我使用--auth参数运行mongod时,即使在验证后我也无法执行简单的操作,例如“show users” ”。但是如果我在没有--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**

4 个答案:

答案 0 :(得分:8)

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

答案 1 :(得分:7)

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

此命令将以admin身份为您提供任何数据库的所有权限。

答案 2 :(得分:0)

我认为您的管理员用户尚未配置为mongo说。

我刚刚在另一个帖子中回答了一个问题并逐步解释: Not authorized for query on admin.system.namespaces on mongodb

试一试。

答案 3 :(得分:0)

不是针对OP,而是针对那些在互联网上搜索

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

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

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

我需要做的是

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

同一件事将适用于mongodump。关键是它默认会尝试连接到admin数据库,而这可能并不是您要尝试的。

相关问题