mongodb uri in fly secrets giving me problems

hello!
my app i am deploying to fly uses a connection to mongodb atlas as an ETL layer and i set the URI string in my local .env for development which works flawlessly. it is encapsulated in double quotes and uses my login and password.
when i add this secret to fly my app completely breaks and the app refuses to start.
is there some secret for using parametized strings as secret variables in fly or potentially i’m just doing it wrong? does mongo need to be whitelisted or something?

Thank you for reading!

Hey, when you did fly secrets set FOO=BAR, did you wrap your secrets in quotes? If so, that’s the problem.

1 Like

i DID wrap them in double quotes. i did this cause fly yelled at me to not use & as a char i think.

fly secrets set MONGODB_URI="connection string here"

what is the proper way to handle this?

Sorry, flyctl properly handles quotes.

I have a separate thread going where I am also trying to get fly connected to my MongoDB Atlas instance, no joy yet

1 Like

ah i think i looked at your but wasn’t sure if we were asking the same thing. thanks for the heads up.

What does the client code for your mongo client look like?

they follow the format as follows
mongodb+srv://username:password@cluster0.mongodb.net/mydb?retryWrites=true&w=majority

so for setting the fly secret i did the following

fly secrets set MONGODB_URI="mongodb+srv://username:password@cluster0.mongodb.net/mydb?retryWrites=true&w=majority"

I mean the code that creates the mongo client.

i don’t see how that is relevant or what you are really asking. we know the issue is with how fly handles the secret. this works perfectly in dev with local env.

I’m asking b/c I need more context; we’re not next to each other. It’s almost impossible to debug w/ just my imagination.

i think i see what you’re suggesting… i could try to compile the URI in code rather than storing the entire thing. i will give that a shot.

@jmerritt decent resource here Backend Deployment - Fly.io and Mongo Atlas - HackMD

Added databases

ok I got my instance working:

  • I added a hardcoded fail over for my app to use a Mongo Connection string if it could not find it in the .env file
  • I had to add my https://MYAPP.fly.dev to google OAuth white lists
  • had to also add several other items to the [env] section of the fly.toml file

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.