Hello,
I am currently using app platform with mongodb managed database and I am facing issues while trying to connect on the database from my nodejs component linked to the mongodb managed database.
The issue come from the certificate : I can’t upload it on the app platform component so I need to use the ‘CA_CERT’ database env variable (https://docs.digitalocean.com/products/app-platform/how-to/use-environment-variables/)
While doing this, I am facing a new issue : the env variable is displaying the whole certificate in a bad format (not even a path) and I need to clean it right after and I am literally doing :
// cert formatter which looks really ugly
const cert = env('CA_CERT').replaceAll(' ', '\n').replace('BEGIN\n', 'BEGIN ').replace('END\n', 'END ');
mongoose.connect(url, {
useNewUrlParser: true,
useUnifiedTopology: true,
sslCA: cert
});
with ssl=true
instead of tls=true
in mongo url.
I am looking for a better solution or an explanation about how should I use the app platform with mongodb managed database which is not shown on docs (https://docs.digitalocean.com/products/databases/mongodb/how-to/connect/).
Also, I appreciate these kind of articles (https://www.digitalocean.com/community/tech_talks/making-a-node-mongodb-app-on-digitalocean) but it is only for a local purpose and with the cert locally downloaded.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hello @aellanglet ,
To begin with, the env variable added is using the direct value instead we recommend you to use the bindable variable. You can update the env variable as follows:
You can add the following env variable to pass the SSL CA certificate:
Regarding the code, I see you are not passing the SSL CA certificate so the database connection is failing for some reason. I would recommend you to update it as follows and check the connection:
Hope this helps! Regarding the documentation, I shall pass this to our team internally.
Cheers, Sri Charan