By dev.dark.dao
I need a certificate to connect to the MongoDB Cluster. How to create it?
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!
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'
...
backend:
build:
context: .
dockerfile: Dockerfile
dns:
- 8.8.8.8
- 4.4.4.4
Mongoose connection code for DigitalOcean Mongodb Cluster
import mongoose from 'mongoose'
...
const mongoConnectionString = 'CONNECTION_STRING_FROM_DIGITAL_OCEAN_ADMIN_PANEL';
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 => {
console.log('MONGO_ERROR_CONNECTION')
})
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:
https://docs.digitalocean.com/products/databases/mongodb/how-to/connect/#connect-to-the-database
Let me know if you have any questions.
Best,
Bobby
This comment has been deleted
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.