Alexander Mills
Alexander Mills

Reputation: 100020

MongoDB user roles

I am trying to grant my users of my app a role that will allow them to do anything they want in a particular database.

Also, I assume for my simple application, when the user first registers with the application, I then, and only then, grant them that role?

What is shorthand in JavaScript to grant a user a "do anything" role for a particular database?

use admin
db.grantRolesToUser(
  "myUsersName",
  [
    {
      role: "doAnythingAndEverything", db: "userDBName"
    },
  ]
)

Upvotes: 1

Views: 9189

Answers (1)

anhlc
anhlc

Reputation: 14449

The role combining every privileges (readWrite, dbAdmin and userAdmin) for a specific database is "dbOwner". As far as I know, there is no shorthand to grant a role other than db.grantRolesToUser

use admin
db.grantRolesToUser(
  "myUsersName",
  [
    {
      role: "dbOwner", db: "userDBName"
    },
  ]
);

Upvotes: 5

Related Questions