Is there an easy way to ask mongod, “give me a list of all databases that user ‘abc’ is a member of”?
Hi Michael,
If you have access to the userAdmin or userAdminAnyDatabase role for the admin database, you should be able to run find() in system.users collection.
In Mongo Shell, an example query to list of all databases user abc having a role(s) in:
use admin;
db.system.users.find(
/* Filter user 'abc' only */
{user:"abc"},
/* Project only db names in roles */
{"roles.db":1}
);
You may want to get the role for the related database as well for completeness. As a user can be listed to have an involvement in database 'foo' but may not have write access to it.
You may find the list of the available built-in roles useful.
Best regards,
Wan.