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
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/mongodb/shell-methods/user-management/db-getUsers.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics