MongoDB: db.getUsers() method
db.getUsers()
The db.getUsers() method is used to return information for all users associated with a database.
Syntax:
db.getUsers()
Parameter:
Name | Description | Required / Optional |
Type |
---|---|---|---|
username | The name of the user for which to retrieve information. | Required | string |
Example: MongoDB: db.getUsers() method
The following statement returns information for all the users in the database.
db.getUsers();
Output:
db.getUsers(); { "_id" : "test.mynewuser1", "user" : "mynewuser1", "db" : "test", "roles" : [ ] }, { "_id" : "test.mynewuser", "user" : "mynewuser", "db" : "test", "roles" : [ { "role" : "read", "db" : "orders" }, { "role" : "readWrite", "db" : "test" }, { "role" : "dbAdmin", "db" : "test" } ] }
Retrieve the restaurants data from here
Required Access
To view another user’s information, you must have the viewUser action on the other user’s database.
Previous:
db.getUser() method
Next:
Mongodb Role Management db.createRole() method
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join