Restrict Write Operations to MongoDB将写入操作限制到MongoDB
On this page本页内容
You can use the 您可以使用readOnly
option to prevent users from performing write operations to your MongoDB deployment through Compass. readOnly
选项来防止用户通过Compass对MongoDB部署执行写操作。If you enable the 如果启用readOnly
option, users cannot modify documents, create indexes, or specify validation rules.readOnly
选项,则用户无法修改文档、创建索引或指定验证规则。
About This Task关于此任务
By default, Compass disables the 默认情况下,Compass会禁用readOnly
option.readOnly
选项。
If the 如果启用了readOnly
option is enabled, you cannot enable the following options:readOnly
选项,则无法启用以下选项:
Procedure过程
You can enable the 您可以在以下任一位置启用readOnly
option in either:readOnly
选项:
The Compass Settings panelCompass设置面板- The
command line命令行 - A configuration file
Compass Settings PanelCompass设置面板
In the Compass top menu bar, click MongoDB Compass.在Compass顶部菜单栏中,单击“MongoDB Compass”。

Alternatively, you can use keyboard shortcuts to open the Settings panel:或者,您可以使用键盘快捷键打开“设置”面板:
- Windows / Linux:
Ctrl
+,
- Mac:
⌘
+,
In the MongoDB Compass menu, click Settings.在“MongoDB Compass”菜单中,单击“设置”。
Compass opens a dialog box where you can configure your MongoDB Compass settings.Compass会打开一个对话框,您可以在其中配置MongoDB Compass设置。
Toggle Set Read-Only Mode.切换“设置只读模式”。
Click Save.单击“保存”。
Command Line命令行
The following command starts Compass from the command line and sets the 以下命令从命令行启动Compass并设置--readOnly
option:--readOnly
选项:
<path-to-Compass-executable> --readOnly
The name and filepath of the Compass executable depend on your operating system.Compass可执行文件的名称和文件路径取决于您的操作系统。
Configuration File配置文件
You can specify the Compass configuration file in either EJSON or YAML format. 您可以以EJSON或YAML格式指定Compass配置文件。The following configurations set the 以下配置将readOnly
option to true
:readOnly
选项设置为true
:
EJSON
{ "readOnly": true }
YAML
readOnly: true
Learn More了解更多信息
To learn more about the MongoDB Compass configuration file, see Configuration File Settings.要了解有关MongoDB Compass配置文件的更多信息,请参阅配置文件设置。