Hide Credentials in Your Connection String在连接字符串中隐藏凭据
On this page本页内容
When you paste a connection string into the MongoDB Compass connection form, Compass shows credentials in plaintext by default. To hide credentials in the connection string, use the 当您将连接字符串粘贴到MongoDB Compass连接表单中时,Compass默认情况下以明文显示凭据。要在连接字符串中隐藏凭据,请使用protectConnectionStrings
option.protectConnectionStrings
选项。
About This Task关于此任务
When 启用protectConnectionStrings
is enabled, users cannot perform the following actions:protectConnectionStrings
后,用户无法执行以下操作:
Edit the connection string in the Compass connection form.在Compass连接窗体中编辑连接字符串。Copy the connection string in the Compass interface.在Compass界面中复制连接字符串。See the credentials when exporting a query.导出查询时请查看凭据。
Procedure过程
To hide your your connection string credentials, enable the 要隐藏连接字符串凭据,请启用protectConnectionStrings
option.protectConnectionStrings
选项。
You can set the 您可以在以下任一位置设置protectConnectionStrings
option in either:protectConnectionStrings
选项:
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 Protect Connection String Secrets.切换“保护连接字符串机密”。
Click Save.单击“保存”。
Command Line Example命令行示例
The following command starts Compass from the command line and sets the 以下命令从命令行启动Compass,并设置--protectConnectionStrings
option:--protectConnectionStrings
选项:
<path-to-Compass-executable> --protectConnectionStrings
The name and filepath of the Compass executable depend on your operating system.Compass可执行文件的名称和文件路径取决于您的操作系统。
Configuration File Example配置文件示例
You can specify the Compass configuration file in either EJSON or YAML format. 您可以以EJSON或YAML格式指定Compass配置文件。The following configurations set the 以下配置将protectConnectionStrings
option to true
:protectConnectionStrings
选项设置为true
:
EJSON
{ "protectConnectionStrings": true }
YAML
protectConnectionStrings: true
Learn More了解更多信息
To learn more about the MongoDB Compass configuration file, see Configuration File Settings.要了解有关MongoDB Compass配置文件的更多信息,请参阅配置文件设置。