MongoDB not authorized for query admin.system.users

空扰寡人 提交于 2019-12-30 07:19:08

问题


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.

> 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**

回答1:


Firstly you should to run mongod on localhost without --auth and create user with necessary roles that you needed. In your case you should add userAdminAnyDatabase or userAdmin role. Than you could run mongod with --auth and authenticate by this user for have remote access to system.users collections.
You could read about it here.




回答2:


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

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




回答3:


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

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

try it.




回答4:


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

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 --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 admin DB by default, and that might not be what you're trying to do.



来源:https://stackoverflow.com/questions/22067612/mongodb-not-authorized-for-query-admin-system-users

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!