'MongoDB Client disconnects when I open another connection
I have an Nx project where I have two apps. Both connect to a different MongoDB instance like this:
const mongoClient = new MongoClient(url, {
keepAlive: true,
});
await mongoClient.connect();
await mongoClient.db("admin").command({ ping: 1 });
logger.info(`Connected to MongoDB at ${url}`);
My problem is that if I start one of the services it runs perfectly, but if I start the other one (which has the same code for connecting, but tries to connect to a different MongoDB instance) the other service disconnects!
What am I doing wrong? I need both services to connect to their own MongoDB instance.
This is what I'm getting:
MongoNotConnectedError: MongoClient must be connected to perform this operation
and I'm running both services as a standalone node.js app with Nx:
nx serve projectA
nx serve projectB
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
