You can use the Compass CLI to export saved connections. Colleagues can import your saved connections, or you can use them yourself in your other workspaces.您可以使用Compass CLI导出已保存的连接。同事可以导入您保存的连接,您也可以在其他工作区中自己使用它们。
About This Task关于此任务
When you export saved connections, Compass exports the list of connections as a JSON file.导出已保存的连接时,Compass会将连接列表导出为JSON文件。
By default, when you export saved connections, passwords are included in plaintext. To protect sensitive connection information, encrypt the exported file with a passphrase.默认情况下,导出已保存的连接时,密码将以明文形式包含。为了保护敏感的连接信息,请使用密码对导出的文件进行加密。
Export Encrypted Saved Connections导出加密的已保存连接
This section shows how to export encrypted saved connections. When you encrypt the export file, users must specify the matching passphrase to import the connections.本节介绍如何导出加密的已保存连接。加密导出文件时,用户必须指定匹配的密码才能导入连接。
Procedure过程
To export encrypted 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将--export-connectionsoption set to the destination of the output file.--export-connections选项设置为输出文件的目标。The--passphraseoption set to a passphrase used to encrypt the output file.--passphrase选项设置为用于加密输出文件的密码。
Your operation should resemble the following prototype:您的操作应该类似于以下原型:
<path-to-Compass-executable> \
--export-connections=<filename> \
--passphrase=<passphrase>Example示例
This example exports saved Compass connections to a file with the path 此示例将保存的Compass连接导出到路径为/tmp/compass-connections/favorites-encrypted.json. The exported file is encrypted with the passphrase abc123./tmp/compass-connections/favorites-encrypted.json的文件中。导出的文件使用密码abc123加密。
Run the following command in the folder containing your MongoDB Compass executable:在包含MongoDB Compass可执行文件的文件夹中运行以下命令:
./MongoDB\ Compass \
--export-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。
You will see this output:您将看到以下输出:
Exporting connections to "/tmp/compass-connections/favorites-encrypted.json" (with passphrase)
Results结果
After the export completes, the 导出完成后,/tmp/compass-connections/favorites-encrypted.json file resembles the following:/tmp/compass-connections/favorites-encrypted.json文件类似于以下内容:
{
"type": "Compass Connections",
"version": {
"$numberInt": "1"
},
"connections": [
{
"id": "5a92e195-3ef5-49ae-aff6-720af362770d",
"connectionOptions": {
"connectionString": "mongodb+srv://jallen@cluster0.ylwlz.mongodb.net/"
},
"favorite": {
"name": "Dochub",
"color": "color7"
},
"lastUsed": {
"$date": {
"$numberLong": "1663785601002"
}
},
"connectionSecrets": "AAGRWyDUI+Jbc9GkvSpEZeFtbvSzqtcOpA+1zLi5fma3AISOOVVBJBPqqh/a6VeNyEcf9TdX6aCqSpagXgMAOmmN0XgkJ4wxwBuSZwZH/h1dlgEFYqEG9Oh88e5z"
},
{
"id": "655f3e6e-b13b-4813-8578-50d896bd9240",
"connectionOptions": {
"connectionString": "mongodb://localhost:27017/"
},
"favorite": {
"name": "Local Host",
"color": "color7"
},
"lastUsed": {
"$date": {
"$numberLong": "1663790327679"
}
},
"connectionSecrets": "AAG63lys6oVtPmCGVs7wYkTCjFU0yXi9rYUYCKuWGNMSNBy4rAZlu06b/qDblON4OBXDJzhPNQ/WKs79veewNw=="
}
]
}
Sensitive connection information is encrypted in the 敏感连接信息在connectionSecrets field.connectionSecrets字段中加密。
Export Unencrypted Saved Connections导出未加密的已保存连接
This section shows how to export unencrypted saved connections. If you do not encrypt the export file, database usernames and passwords are exported in plaintext. Only export unencrypted connections if no other users will have access to the exported file.本节将展示如何导出未加密的已保存连接。如果不加密导出文件,数据库用户名和密码将以明文形式导出。只有当没有其他用户可以访问导出的文件时,才导出未加密的连接。
Procedure过程
To export encrypted 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将--export-connectionsoption set to the destination of the output file.--export-connections选项设置为输出文件的目标。
Your operation should resemble the following prototype:您的操作应该类似于以下原型:
<path-to-Compass-executable> \
--export-connections=<filename>Example示例
This example exports saved Compass connections to a file with the path 此示例将保存的Compass连接导出到路径为/tmp/compass-connections/favorites.json./tmp/compass-connections/favorites.json的文件中。
Run the following command in the folder containing your MongoDB Compass executable:在包含MongoDB Compass可执行文件的文件夹中运行以下命令:
./MongoDB\ Compass \
--export-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。
You will see this output:您将看到以下输出:
Exporting connections to "/tmp/compass-connections/favorites.json" (without passphrase)
Results结果
After the export completes, the 导出完成后,/tmp/compass-connections/favorites.json file resembles the following:/tmp/compass-connections/favorites.json文件类似于以下内容:
{
"type": "Compass Connections",
"version": {
"$numberInt": "1"
},
"connections": [
{
"id": "5a92e195-3ef5-49ae-aff6-720af362770d",
"connectionOptions": {
"connectionString": "<connection string>"
},
"favorite": {
"name": "QA Cluster",
"color": "color7"
},
"lastUsed": {
"$date": {
"$numberLong": "1663785601002"
}
}
},
{
"id": "655f3e6e-b13b-4813-8578-50d896bd9240",
"connectionOptions": {
"connectionString": "mongodb://localhost:27017/"
},
"favorite": {
"name": "Local Host",
"color": "color7"
},
"lastUsed": {
"$date": {
"$numberLong": "1663790327679"
}
}
}
]
}Next Steps后续步骤
To learn how to import exported connections, see Import Saved Connections with the CLI.要了解如何导入导出的连接,请参阅使用CLI导入已保存的连接。