In the MongoDB shell, how do I list all users for the current database that I'm using?
I can't seem to find it anywhere on stackoverflow.
For users created in MongoDB, MongoDB stores all user information, including name , password , and the user's authentication database , in the system. users collection in the admin database. Do not modify this collection directly. To manage users, use the designated user management commands.
To list all collections in Mongo shell, you can use the function getCollectionNames().
To get stats about MongoDB server, type the command db. stats() in MongoDB client. This will show the database name, number of collection and documents in the database.
We can get the information explicitly about the number of connections made to the server by running the command db. serverStatus(). connections from any of the MongoDB Shell connected to the Server.
You can do:
db.getUsers()
or
show users
The both commands print a list of users for the current database. See MongoDB documentation for User Management.
List belong to db users:
use db_name
and db.getUsers()
or show users
List according the authentication type:
db.getUsers({ filter: { mechanisms: "SCRAM-SHA-256" } })
List with the credental:
db.getUsers( {showCredentials: true, filter: { mechanisms: "SCRAM-SHA-256" }} )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With