mongoDb 用户最少 roles/privileges 才能创建新数据库

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

我正在编写一个在一个主 mongoDb 上运行的程序,但可能会创建新的 mongo 数据库。

我想弄清楚 mongoDbUser(我的程序使用)需要什么最低权限才能创建新数据库并对它创建的数据库具有读写访问权限.

您的 mongoDbUser 用户需要角色:readWriteAnyDatabase.

来自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.