How to create SSL certificate on Ubuntu(22.04 (LTS) x64) droplet for Mongo?

I need a certificate to connect to the MongoDB Cluster. How to create it?

Show comments

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Accepted Answer

I solved this problem. When I ran the code directly from Node Js, the connection was successful. When I ran the code from the Docker container, the mongoose did not connect.

You need to add the following dns config to docker compose:

version: '3'
      context: .
      dockerfile: Dockerfile

Mongoose connection code for DigitalOcean Mongodb Cluster

import mongoose from 'mongoose'
const mongoDbName = ''
const mongooseOptions = {
    user: mongoUserLogin,
    pass: mongoUserPassword,
    tls: true,
    dbName: mongoDbName,
    tlsInsecure: true,
    useUnifiedTopology: true,
    useNewUrlParser: true,
    keepAlive: true
mongoose.connect(mongoConnectionString, mongooseOptions)
  .then(() => {
    console.log('Mongo is connected')
  .catch(error => {
Bobby Iliev
Site Moderator
Site Moderator badge
February 15, 2023

Hi there,

In case that you are referring to the Managed MongoDB clusters, there will be no need to generate a new SSL certificate. You will just need to make sure to use a TLS compatible MongoDB client to connect like mongo and specify the --tls flag.

For more information you can follow the docs here:

Let me know if you have any questions.



This comment has been deleted

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up

    Featured on Community

    Get our biweekly newsletter

    Sign up for Infrastructure as a Newsletter.

    Hollie's Hub for Good

    Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

    Become a contributor

    Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

    Welcome to the developer cloud

    DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

    Learn more
    DigitalOcean Cloud Control Panel