Docs Home / Compass / Connect / Favorite Connections / Import & Export

Import Saved Connections with the CLI使用CLI导入已保存的连接

You can use the Compass CLI to import saved connections. This lets you use saved connections from other workspaces or connections used by other team members.

Prerequisite先决条件

To import saved connections, you must first export the connections.要导入已保存的连接,必须先导出连接

Import Encrypted Saved Connections导入加密的已保存连接

Use this procedure to import a list of saved connections that is encrypted with a passphrase.使用此过程可以导入使用密码加密的已保存连接列表。

Procedure过程

To import unencrypted saved connections with the Compass CLI, specify:要使用Compass CLI导入未加密的已保存连接,请指定:

  • The path to the MongoDB Compass executable. The name and filepath of the executable depend on your operating system.MongoDB Compass可执行文件的路径。可执行文件的名称和文件路径取决于您的操作系统。
  • The --import-connections option set to the destination of the file containing saved connections.--import-connections选项设置为包含已保存连接的文件的目标。
  • The --passphrase option set to the passphrase used to encrypt the exported file.--passphrase选项设置为用于加密导出文件的密码。

Your operation should resemble the following prototype:您的操作应该类似于以下原型:

<path-to-Compass-executable> \
--import-connections=<filename> \
--passphrase=<passphrase>

Example示例

The following example imports saved Compass connections from a file with the path /tmp/compass-connections/favorites-encrypted.json that is encrypted with the passphrase abc123.以下示例从路径为/tmp/compass-connections/favorites-encrypted.json的文件中导入已保存的Compass连接,该文件使用密码abc123进行加密。

Run the following command in the folder containing your MongoDB Compass executable:在包含MongoDB Compass可执行文件的文件夹中运行以下命令:

./MongoDB\ Compass \
--import-connections=/tmp/compass-connections/favorites-encrypted.json \
--passphrase=abc123

Note

The name and file path of the executable depend on your operating system. The preceding command is for macOS.可执行文件的名称和文件路径取决于您的操作系统。上述命令适用于macOS。

Results结果

After you run the import command, you will see this output:运行import命令后,您将看到以下输出:

Importing connections from "/tmp/compass-connections/favorites-encrypted.json" (with passphrase)

MongoDB Compass starts and you will see the imported connections under Saved Connections on the Connect screen.MongoDB Compass启动后,您将在Connect屏幕上的“已保存的连接”下看到导入的连接。

Errors错误

When you try to import encrypted saved connections, you may see these errors:当您尝试导入加密的已保存连接时,您可能会看到以下错误:

  • If do not specify a passphrase, you will see this error:如果不指定密码,您将看到此错误:

    Failed to perform operation Be [Error]: Input file contains encrypted
    secrets but no passphrase was provided
  • If you specify an incorrect passphrase, you will see this error:如果您指定了不正确的密码,您将看到此错误:

    Failed to perform operation Be [Error]: Cannot decrypt due to corrupt
    data or wrong passphrase

Import Unencrypted Saved Connections导入未加密的已保存连接

Use this procedure to import a list of saved connections that is not encrypted with a passphrase.使用此过程导入未使用密码加密的已保存连接列表。

Procedure过程

To import unencrypted saved connections with the Compass CLI, specify:要使用Compass CLI导入未加密的已保存连接,请指定:

  • The path to the MongoDB Compass executable. The name and file path of the executable depend on your operating system.MongoDB Compass可执行文件的路径。可执行文件的名称和文件路径取决于您的操作系统。
  • The --import-connections option set to the destination of the file containing saved connections.--import-connections选项设置为包含已保存连接的文件的目标。

Your operation should resemble the following prototype:您的操作应该类似于以下原型:

<path-to-Compass-executable> --import-connections=<filename>

Example示例

The following example imports saved Compass connections from a file with the path /tmp/compass-connections/favorites.json.以下示例从路径为/tmp/compass-connections/favorites.json的文件中导入已保存的Compass连接。

Run the following command in the folder containing your MongoDB Compass executable:在包含MongoDB Compass可执行文件的文件夹中运行以下命令:

./MongoDB\ Compass --import-connections=/tmp/compass-connections/favorites.json

Note

The name and file path of the executable depend on your operating system. The preceding command is for macOS.可执行文件的名称和文件路径取决于您的操作系统。上述命令适用于macOS。

Results结果

After you run the import command, you will see this output:运行import命令后,您将看到以下输出:

Importing connections from "/tmp/compass-connections/favorites.json" (without passphrase)

MongoDB Compass starts and you will see the imported connections under Saved Connections on the Connect screen.MongoDB Compass启动后,您将在Connect屏幕上的“已保存的连接”下看到导入的连接。