Search code examples
mongodbmongodb-security

Minimal roles/privileges for a mongoDb user in order to be able to create new databases


I am writing a program that operates on one main mongoDb but may create new mongo databases.

I am trying to figure out what are the minimal rights that the mongoDbUser (used by my program) needs in order to be able to create new databases and have readWrite access to the databases it has created.


Solution

  • Your mongoDbUser user needs the role: readWriteAnyDatabase.

    From the docs:

    readWriteAnyDatabase

    Provides the same read and write privileges as readWrite on all databases except local and config. readWriteAnyDatabase also provides the listDatabases privilege action on the cluster.