Skip to content

Instantly share code, notes, and snippets.

@shadyrudy
Created January 19, 2023 20:01
Show Gist options
  • Save shadyrudy/7d99d8264a6f2c4eb1419de1cf0390c0 to your computer and use it in GitHub Desktop.
Save shadyrudy/7d99d8264a6f2c4eb1419de1cf0390c0 to your computer and use it in GitHub Desktop.
List all users and roles in MongoDB
// The following MongoDB script displays all users and roles for all databases.
// Appropriate permissions are required to run this script
use admin
// Increase the number of documents returned by the find command
// Use either the legacy mongo shell version or Mongosh version
// Legacy Mongo Shell version
DBQuery.shellBatchSize = 300
// Mongosh version
config.set("displayBatchSize", 300)
// Display all users, along with their databases and roles
db.system.users.find({},{db:1,user:1,roles:1});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment