Docs HomeMongoDB Compass

Hide Credentials in Your Connection String在连接字符串中隐藏凭据

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 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 hide your your connection string credentials, enable the protectConnectionStrings option.要隐藏连接字符串凭据,请启用protectConnectionStrings选项。

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

Compass Settings PanelCompass设置面板

1

In the Compass top menu bar, click MongoDB Compass.在Compass顶部菜单栏中,单击“MongoDB Compass”。

Settings panel location under the MongoDB Compass system menu

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

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

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设置。

3

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

4

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. 您可以以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配置文件的更多信息,请参阅配置文件设置