Setting Up MongoDB with SSL Certificate in Meteor
In this guide, you will learn how to configure Meteor to connect to MongoDB with an SSL certificate for secure communication. We will walk through downloading the SSL certificate from Galaxy Database, placing it in your project, and configuring the settings for secure MongoDB connection.
Step 1: Download the SSL Certificate from Galaxy Database
- Navigate to your MongoDB Overview page on Galaxy Database.
- Find the SSL certificate download link.
Step 2: Create the private
Folder in Your Meteor Project
- Inside the root folder of your Meteor project, create a new folder called
private
. This is where you will store the SSL certificate for secure communication with MongoDB.
- Place the downloaded SSL certificate file inside this
private
folder. For the purposes of this tutorial, we will assume the certificate is namedcertificate.pem
.
- We also recommend leaving the settings.json in this folder*
Step 3: Update the settings.json
File
You need to configure Meteor's settings.json
file to properly use the SSL certificate. The following configuration enables SSL and specifies the certificate file.
- In the root of your Meteor project, open (or create) the
settings.json
file. - Add the following configuration:
{
"packages": {
"mongo": {
"options": {
"tls": true,
"tlsCAFileAsset": "certificate.pem"
}
}
},
"galaxy.meteor.com": {
"env": {
"MONGO_URL": "mongodb://user:pass@todo1.mongodb.galaxy-cloud.io:30020,todo2.mongodb.galaxy-cloud.io:30020,todo2.mongodb.galaxy-cloud.io:30020/simpletasksssl_ssl?replicaSet=todo_app&ssl=true&authSource=admin"
}
}
}
- tlsCAFileAsset: This option specifies that the SSL certificate is located inside the
private
folder of your project. - MONGO_URL: This is your MongoDB connection string. Ensure that the string includes
ssl=true
andauthSource=admin
to enable SSL and authenticate against the correct database.
3.1. When using PushToDeploy, you need to setup your settings.json file path following these steps:
- On the fourth step, click on Advanced Options:
- Next step, you need to inform the path that your settings.json file is located on the Deploy Arguments field
On that field you could insert --settings private/settings.json
if your file is inside the private directory.
Step 4: Verify MongoDB Connection String
When connecting to MongoDB, you must include certain parameters in the connection string to ensure SSL is used correctly:
- Add the following parameters at the end of your MongoDB connection string:
&authSource=admin
This tells MongoDB to authenticate with the admin database.
Conclusion
Once these steps are complete, your Meteor app will be securely connected to your MongoDB instance using SSL. This configuration ensures that all data between your app and the database is encrypted, protecting it from potential security threats.
Make sure to test your connection to verify that everything is set up correctly! This way, you can now deploy your application to the Galaxy and check that everything works correctly.
meteor deploy appname --settings private/settings.json
Updated on: 11/04/2025