MongoDB.live, free & fully virtual. June 9th - 10th. Register Now MongoDB.live, free & fully virtual. June 9th - 10th. Register Now

Python get users of database

I want to create an admin application to monitor data collection. For this the user registration process is based on the database access i.e, when we create a new database user through MongoDB atlas, they will immediately be able to log into the admin application with their database username and password. How do I get a mongo document/response containing the list of database users and their hashed passwords using python?

You use PyMongo’s command helper to run the usersInfo (https://docs.mongodb.com/manual/reference/command/usersInfo/) command with showCredentials: true to get this information. Note that the user that runs the usersInfo command must have certain privileges to be able to see other user’s information: https://docs.mongodb.com/manual/reference/command/usersInfo/#required-access