w3resource
MongoDB Tutorial

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



New Content: Composer: Dependency manager for PHP, R Programming


bedava porno