0

I'm working on a NestJS microservices architecture and encountering issues connecting to MongoDB Atlas. The same MongoDB URI configuration works with a monolithic NestJS project, but it fails in my microservices setup, even with all IPs whitelisted in MongoDB Atlas.

I have tried a few solutions:

  1. Verified that .env variables (like MongoDB URI) are loaded correctly in each service.

  2. Tested with both a local MongoDB instance and MongoDB Atlas.

  3. Confirmed that the MongoDB Atlas connection works in a single-project structure (monolith) but fails in the microservices setup.

Here’s how I’m setting up the MongooseModule for each service:

MongooseModule.forRoot(\`mongodb+srv://${process.env.MONGODB_USERNAME}:${process.env.MONGODB_PASSWORD}@cluster.f4rts7w.mongodb.net/${process.env.MONGODB_CROWDFUNDING_DATABASE}?retryWrites=true&w=majority\`)

Could the problem be related to differences in environment variable management or module loading in a microservices setup? Any suggestions or troubleshooting steps would be greatly appreciated!

Wernfried Domscheit
60.5k10 gold badges93 silver badges132 bronze badges
asked Nov 8, 2024 at 10:40
2
  • 1
    Please provide enough code so others can better understand or reproduce the problem. Commented Nov 8, 2024 at 11:03
  • Can you connect with other tools, e.g. mongo shell mongosh? Commented Nov 10, 2024 at 10:24

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.