mongodb 中没有用户具有管理员权限 - 如何创建具有管理员权限的用户?

No user in mongodb with admin privileges - how can create an user with admin privileges?

起初 mongodb 中没有身份验证,所以我为具有 readWrite 角色的数据库创建了一个。

现在我想为其他数据库创建更多用户,但由于该用户没有创建其他用户的权限,我被卡住了。

The documentation 清楚地说:

With access control enabled, ensure you have a user with userAdmin or userAdminAnyDatabase role in the admin database. This user can administrate user and roles such as: create users, grant or revoke roles from users, and create or modify customs roles.

如果您还没有创建这样的用户,您现在无法在启用身份验证和访问权限的情况下创建它。我想您需要在未启用身份验证的情况下重新启动 MongoDB 服务器,创建该管理员用户,然后在启用身份验证的情况下再次重新启动 MongoDB 服务器。

我强烈建议您先阅读完整的 documentation how to enable authentication 以了解完整的概念,然后再逐步执行。否则它可能会造成混乱并造成您当前处于锁定状态并且无法继续所有操作的状态。