Find user script
The following script lists users on a MongoDB server, including their databases and roles. Appropriate permissions are required to run it.
use admin
// Increase the number of documents displayed per batch.
// Legacy mongo shell:
DBQuery.shellBatchSize = 300
// mongosh:
config.set("displayBatchSize", 300)
// Display users, databases, and roles.
db.system.users.find({}, { db: 1, user: 1, roles: 1 });
The original script is also on GitHub Gist.
Results
The results are a list of user names, databases, and roles by database.
