Question

Connecting to Managed MongoDB with ENV

I have been trying to connect the managed Monogodb database to my App. I have done all the trusted sources setup, and the platform automatically added an ENV as DATABASE_URL with a key ${DATABASE_URL}. It also added another with my db name under the same key DATABASE_URL with a key like ${dtabasename.DATABASE_URL}. I tried different things to get it to connect. My database is setup so i need to point to the url with a /games, as that is where all my collections are. I went to the console and put in echo $DATABASE_URL and it printed out my db url with the certificate, but wasn’t at the correct directory of it. It pointed to /testing. Since then I have tried other things, and the console no longer prints out the url and certificate, it just returns DATABASE_URL like the ENV doesn’t work anymore. echo $APP_URL still work.

How do I set this up? I have it running locally with the certifcate and everything, I just can’t get it to work on the App Platform.


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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

I am very close to getting my mongodb database connected in the App Platform. I built up the env value like this

Don’t mind the “” and the spaces, I am doing that so it will post, it seems like when I have a string like that in a post, it messes up.

“mongodb+srv:// $ {db-mongodb.USERNAME}: $ {db-mongodb.PASSWORD}@${db-mongodb.HOSTNAME}/testing? authSource=admin& replicaSet=db-mongodb &tls=true &tlsCAFile= $ {db-mongodb.CA_CERT}”

I get this error Error: ENOENT: no such file or directory, open ‘-----BEGIN CERTIFICATE-----’ which makes me think there is another thing like tlsCAFile but to point to a string instead, as the App Platform is giving me this CA_CERT through the ENV. I think it will work once I get this.