[英]MongoDB not authorized for query admin.system.users
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".我对 MongoDb 有点陌生,我正在使用 MongoDb v.2.4。这里的问题是,当我使用 --auth 参数运行 mongod 时,即使经过身份验证,我也无法执行诸如“显示用户”之类的简单操作。 But works fine if I run mongod without --auth parameter.但是如果我在没有 --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**
Firstly you should to run mongod on localhost without --auth
and create user with necessary roles that you needed.首先,您应该在没有--auth
情况下在 localhost 上运行 mongod 并创建具有您需要的必要角色的用户。 In your case you should add userAdminAnyDatabase
or userAdmin
role.在您的情况下,您应该添加userAdminAnyDatabase
或userAdmin
角色。 Than you could run mongod with --auth
and authenticate by this user for have remote access to system.users
collections.您可以使用--auth
运行 mongod 并通过此用户进行身份验证以远程访问system.users
集合。
You could read about it here .你可以在这里阅读它。
> use admin
switched to db admin
> db.grantRolesToUser("your_admin_name" ,[ "root"])
This command will give you all privileges on any db as admin.此命令将以管理员身份授予您对任何数据库的所有权限。
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.尝试一下。
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
.同样的事情也适用于mongodump
。 The point is that it tries to connect to the admin
DB by default, and that might not be what you're trying to do.关键是它默认尝试连接到admin
数据库,而这可能不是您想要做的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.