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 从MongoDB 8.0开始,您可以使用directShardOperations role to perform maintenance operations that require you to execute commands directly against a shard.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 MongoDB将通过mongos in the admin database of the config servers.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 要列出所有分片本地用户,请直接连接到相应的分片并运行前面的命令。MongoDB将分片本地用户存储在分片本身的admin database of the shard itself. 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无法访问。