Docs Menu

Docs HomeView & Analyze DataMongoDB Compass

Export Saved Connections with the CLI

On this page

  • About This Task
  • Export Encrypted Saved Connections
  • Procedure
  • Example
  • Export Unencrypted Saved Connections
  • Procedure
  • Example
  • Next Steps

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.

When you export saved connections, Compass exports the list of connections as a JSON file.

By default, when you export saved connections, passwords are included in plaintext. To protect sensitive connection information, encrypt the exported file with a passphrase.

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.

To export encrypted saved connections with the Compass CLI, specify:

  • The path to the MongoDB Compass executable. 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.

  • The --passphrase option set to a passphrase used to encrypt the output file.

Your operation should resemble the following prototype:

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

This example exports saved Compass connections to a file with the path /tmp/compass-connections/favorites-encrypted.json. The exported file is encrypted with the passphrase abc123.

Run the following command in the folder containing your MongoDB Compass executable:

./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.

You will see this output:

Exporting connections to "/tmp/compass-connections/favorites-encrypted.json" (with passphrase)

After the export completes, the /tmp/compass-connections/favorites-encrypted.json file resembles the following:

{
"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.

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.

To export encrypted saved connections with the Compass CLI, specify:

  • The path to the MongoDB Compass executable. 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.

Your operation should resemble the following prototype:

<path-to-Compass-executable> \
--export-connections=<filename>

This example exports saved Compass connections to a file with the path /tmp/compass-connections/favorites.json.

Run the following command in the folder containing your MongoDB Compass executable:

./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.

You will see this output:

Exporting connections to "/tmp/compass-connections/favorites.json" (without passphrase)

After the export completes, the /tmp/compass-connections/favorites.json file resembles the following:

{
"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"
}
}
}
]
}

To learn how to import exported connections, see Import Saved Connections with the CLI.

← Import Saved Connections in Compass