w3resource
MongoDB Tutorial

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



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


bedava porno