MongoDB: db.getUser() method
db.getUser()
The db.getUser() method is used to return user information about the specified user from a database. The user must exist on the database on which the method runs.
Syntax:
db.getUser(username)
Parameters:
Name | Description | Required / Optional |
Type |
---|---|---|---|
username | The name of the user for which to retrieve information. | Required | string |
Example: MongoDB: db.getUser() method
The following sequence of operations returns information about the mynewuser user on the test database
use test
db.getUser("mynewuser");
Output:
db.getUser("mynewuser"); "_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.revokeRolesFromUser() method
Next:
db.getUsers() 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