How to set up mongodb Managed Database (with cert) with App Platform


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 (

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 (

Also, I appreciate these kind of articles ( but it is only for a local purpose and with the cert locally downloaded.


Submit an 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:

VALUES: ${mymongodb.HOSTNAME}

VALUES: ${mymongodb.PORT}

VALUES: ${mymongodb.DATABASE}

VALUES: ${mymongodb.USERNAME}

VALUES: ${mymongodb.PASSWORD}


You can add the following env variable to pass the SSL CA certificate:

VALUES: ${mymongodb.CA_CERT}

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:

module.exports = ({ env }) => ({
  defaultConnection: 'default',
  connections: {
    default: {
      connector: 'mongoose',
      settings: {
        uri: env('DATABASE_URI'),
        srv: env.bool('DATABASE_SRV', true),
        port:'DATABASE_PORT', 27017),
        database: env('DATABASE_NAME'),
      options: {
        authenticationDatabase: env('AUTHENTICATION_DATABASE', null),
        ssl: env.bool('DATABASE_SSL', true),
        sslCA: env('CA_CERT'),

Hope this helps! Regarding the documentation, I shall pass this to our team internally.

Cheers, Sri Charan