Docs Home / Compass / Customize

Secure Your Connection String保护您的连接字符串

When you paste a connection string into the MongoDB Compass connection form, Compass shows credentials in plaintext by default. To hide your credentials and secure your connection string, use the protectConnectionStrings option.当您将连接字符串粘贴到MongoDB Compass连接表单中时,Compass默认以明文显示凭据。要隐藏凭据并保护连接字符串,请使用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 secure your connection string, enable the protectConnectionStrings option.要保护连接字符串,请启用protectConnectionStrings选项。

You can set the protectConnectionStrings option in either:您可以在以下任一位置设置protectConnectionStrings选项:

Compass Settings PanelCompass设置面板

1

To open the MongoDB Compass Settings Panel, click the gear icon on the left column of the Compass home screen.要打开MongoDB Compass设置面板,请单击Compass主屏幕左列上的齿轮图标。

Settings gear icon location on MongoDB Compass UI

Alternatively, you can use keyboard shortcuts to open the Settings panel:或者,您可以使用键盘快捷键打开“设置”面板:

  • Windows / Linux: Ctrl + ,
  • Mac: + ,

Compass opens a dialog box where you can configure your MongoDB Compass settings.Compass打开一个对话框,您可以在其中配置MongoDB Compass设置。

2

Toggle Protect Connection String Secrets.切换“保护连接字符串机密”。

3

Click Save.单击“保存”。

Command Line Example命令行示例

The following command starts Compass from the command line and sets the --protectConnectionStrings option:以下命令从命令行启动Compass并设置--protectConnectionStrings选项:

<path-to-Compass-executable> --protectConnectionStrings

Note

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. The following configurations set the protectConnectionStrings option to true:您可以以EJSON或YAML格式指定Compass配置文件。以下配置将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配置文件的更多信息,请参阅配置文件设置