Import Saved Connections with the CLI使用CLI导入保存的连接
On this page本页内容
You can use the Compass CLI to import saved connections. 您可以使用Compass CLI导入保存的连接。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
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启动,您将在“连接”屏幕上的“保存的连接”下看到导入的连接。
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 providedIf you specify an incorrect passphrase, you will see this error:如果您指定的密码短语不正确,您将看到以下错误:Failed to perform operation Be [Error]: Cannot decrypt due to corrupt
data or wrong passphraseImport 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.MongoDB Compass可执行文件的路径。The name and file path of the executable depend on your operating system.可执行文件的名称和文件路径取决于您的操作系统。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
NoteThe 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启动,您将在“连接”屏幕上的“保存的连接”下看到导入的连接。