MongoDB未授权查询admin.system.users

Ano*_*der 3 authentication mongodb 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**
Run Code Online (Sandbox Code Playgroud)

siv*_*ivi 9

> use admin
switched to db admin
> db.grantRolesToUser("your_admin_name" ,[ "root"])
Run Code Online (Sandbox Code Playgroud)

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


Iva*_*Srb 8

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