Reputation: 1
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:
Verified that .env
variables (like MongoDB URI) are loaded correctly in each service.
Tested with both a local MongoDB instance and MongoDB Atlas.
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!
Upvotes: 0
Views: 34