mongodb使用通配符角色(如mysql)授予all

mongodb使用通配符角色(如mysql)授予all,mongodb,Mongodb,是否可以授予mongodb中的用户使用某种正则表达式访问多个数据库? 例如,在MySql中,我可以使用 grant all on `example\_%`.* to `example`@`localhost`; 我不确定在MongoDB中是否有这样做的方法,因为设置用户角色时db值必须是字符串。但是,您可以编写脚本来帮助实现相同的结果。我想到了这个(脚本本身很小,但是,注释和日志使它看起来很长): 您可以按如下方式运行脚本: // Replace <host> and <po

是否可以授予mongodb中的用户使用某种正则表达式访问多个数据库? 例如,在MySql中,我可以使用

grant all on `example\_%`.* to `example`@`localhost`;

我不确定在MongoDB中是否有这样做的方法,因为设置用户角色时db值必须是字符串。但是,您可以编写脚本来帮助实现相同的结果。我想到了这个(脚本本身很小,但是,注释和日志使它看起来很长):

您可以按如下方式运行脚本:

// Replace <host> and <port> with the host and port values of your mongoDB server. 
// Replace <adminUserName> with the userName of the admin user
mongo <host>:<port>/admin script.js -u <adminUserName> --authenticationDatabase "admin" -p

//将和替换为mongoDB服务器的主机和端口值。
//替换为管理员用户的用户名
mongo:/admin script.js-u--authenticationDatabase“admin”-p
运行上述命令后会出现密码提示,您应该输入管理员用户的密码

// Replace <host> and <port> with the host and port values of your mongoDB server. 
// Replace <adminUserName> with the userName of the admin user
mongo <host>:<port>/admin script.js -u <adminUserName> --authenticationDatabase "admin" -p