How to use Show Command In Databases
Let’s walk through an example of listing users in a sample MongoDB database named mydatabase.
Connect to MongoDB and switch to the mydatabase database:
mongo
> use mydatabase
List all users configured for the mydatabase database:
> show users
Sample Output
{
"_id" : "mydatabase.user",
"userId" : UUID("8cf6e0b8-1e05-4d34-884b-54dcd6b0b1cf"),
"user" : "user1",
"db" : "mydatabase",
"roles" : [
{
"role" : "readWrite",
"db" : "mydatabase"
}
],
"mechanisms" : [
"SCRAM-SHA-256"
]
}
In this example:
- The show users command displays detailed information about each user configured for the mydatabase database.
- Each user entry includes:
- _id: Unique identifier for the user.
- user: Username.
- db: Database associated with the user.
- roles: Array of roles assigned to the user within the specified database.
- mechanisms: Authentication mechanisms enabled for the user.
How to List all Users in the Mongo Shell
In MongoDB, user management is an essential aspect of database administration, allowing administrators to control access and permissions for different users. The Mongo Shell provides a powerful interface to interact with MongoDB including managing users.
In this article, we’ll explore how to list all users in the Mongo Shell by covering concepts, examples to understand the process effectively.