Mongodb – what roles the user to grant access to all databases

mongodbmongodb-3.6

I have created mongouser as testuser with below roles. I want to give access for new databases for this user. what roles the user to grant access to all databases.

db.createUser({ user: "testuser" , pwd: "testuser", roles: ["dbAdminAnyDatabase", "readWriteAnyDatabase", "enableSharding"]});

Best Answer

I have created mongouser as testuser with below roles. I want to give access for new databases for this user. what roles the user to grant access to all databases.

db.createUser({ user: "testuser" , pwd: "testuser", roles: ["dbAdminAnyDatabase", "readWriteAnyDatabase", "enableSharding"]});

As per MongoDB documentation here MongoDB grants access to data and commands through role-based authorization and provides built-in roles that provide the different levels of access commonly needed in a database system. You can additionally create User-defined roles.

A role grants privileges to perform sets of actions on defined resources. A given role applies to the database on which it is defined and can grant access down to a collection level of granularity.

dbAdminAnyDatabase

Provides the same privileges as dbAdmin on all databases except local and config. The role also provides the listDatabases action on the cluster as a whole.

Changed in version 3.4: Prior to 3.4, dbAdminAnyDatabase includes local and config databases. To provide dbAdmin privileges on the local database, create a user in the admin database with dbAdmin role in the local database. See also clusterManager and clusterMonitor role for access to the config and local databases.

For further your ref here, here and here