mongodbHow to list MongoDB users?
MongoDB users can be listed using the db.getUsers()
command. This command will return a list of all users in the current database.
Example
> use mydb
switched to db mydb
> db.getUsers()
[
{
"_id" : "mydb.user1",
"user" : "user1",
"db" : "mydb",
"roles" : [
{
"role" : "readWrite",
"db" : "mydb"
}
]
},
{
"_id" : "mydb.user2",
"user" : "user2",
"db" : "mydb",
"roles" : [
{
"role" : "readWrite",
"db" : "mydb"
}
]
}
]
Code explanation
db.getUsers()
: command to list all users in the current database
Helpful links
More of Mongodb
- How to use watch in MongoDB?
- How to use unwind in MongoDB?
- How to convert MongoDB ObjectId to string?
- How to remove a field from MongoDB?
- How to work with time series data in MongoDB?
- How to implement pagination in MongoDB?
- How to implement one-to-many relation in MongoDB?
- How to use the limit operator in MongoDB?
- How to perform a health check for MongoDB?
- How to use MongoDB queue?
See more codes...