更新时间:2023-12-01 15:56:46
首先,你应该要在本地主机上运行的mongod没有 - AUTH
并创建用户提供必要的 中的角色,你需要的。在你的情况,你应该添加 userAdminAnyDatabase
或 userAdmin
的作用。比你可以用运行的mongod - AUTH
并通过此用户身份验证有 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". 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**
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.