Export Saved Connections with the CLI使用CLI导出保存的连接
On this page本页内容
You can use the Compass CLI to export saved connections. 您可以使用Compass CLI导出保存的连接。Colleagues can import your saved connections, or you can use them yourself in your other workspaces.同事可以导入您保存的连接,也可以在其他工作区中自己使用它们。
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.MongoDB Compass可执行文件的路径。The name and file path of the executable depend on your operating system.可执行文件的名称和文件路径取决于您的操作系统。The将--export-connections
option set to the destination of the output file.--export-connections
选项设置为输出文件的目标。The--passphrase
option 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
. /tmp/compass-connections/favorites-encrypted.json
的文件中。The exported file is encrypted with the passphrase 导出的文件使用密码abc123
.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
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.MongoDB Compass可执行文件的路径。The name and file path of the executable depend on your operating system.可执行文件的名称和文件路径取决于您的操作系统。The将--export-connections
option 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
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导入保存的连接。