Database Manual / Self-Managed Deployments / Security / Authentication / Users

List Users in Self-Managed Deployments列出自我管理部署中的用户

To list all users, use mongosh to query the system.users collection:要列出所有用户,请使用mongosh查询system.users集合:

Before You Begin开始之前

Starting in MongoDB 8.0, you can use the directShardOperations role to perform maintenance operations that require you to execute commands directly against a shard.从MongoDB 8.0开始,您可以使用directShardOperations角色执行维护操作,这些操作要求您直接对分片执行命令。

Warning

Running commands using the directShardOperations role can cause your cluster to stop working correctly and may cause data corruption. Only use the directShardOperations role for maintenance purposes or under the guidance of MongoDB support. Once you are done performing maintenance operations, stop using the directShardOperations role.使用directShardOperations角色运行命令可能会导致集群停止正常工作,并可能导致数据损坏。仅将directShardOperations角色用于维护目的或在MongoDB支持的指导下使用。完成维护操作后,停止使用directShardOperations角色。

Steps步骤

use admin
db.system.users.find()

Important

Do not modify the system.users collection directly. To manage users, use the designated user management commands.不要直接修改system.users集合。要管理用户,请使用指定的用户管理命令。

To list all users of a sharded cluster that were created through a mongos, connect to a mongos and run the preceding command. 要列出通过mongos创建的分片集群的所有用户,请连接到mongos并运行上述命令。MongoDB stores users that are created through a mongos in the admin database of the config servers.MongoDB将通过mongos创建的用户存储在配置服务器admin数据库中。

To list all shard local users, connect to the respective shard directly and run the preceding command. MongoDB stores shard local users in the admin database of the shard itself. 要列出所有分片本地用户,请直接连接到相应的分片并运行前面的命令。MongoDB将分片本地用户存储在分片本身的admin数据库中。These shard local users are independent from the users added to the sharded cluster through a mongos. 这些分片本地用户独立于通过mongos添加到分片集群的用户。Shard local users are local to the shard and are inaccessible to mongos.分片本地用户是分片的本地用户,mongos无法访问。