Search code examples
mongodbmlabmongodb-roles

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"
    },
  ]
)

Solution

  • 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"
        },
      ]
    );