How to use getUsers() Command In Databases
Another way to list users in MongoDB is by using the getUsers()
method. This method retrieves a list of users from the current database.
use admin
db.getUsers()
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 db.getUsers()
method retrieves a list of users from the admin
database.
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.