Too many connections using node driver with atlas

I’ve opened an issue on the mongo remix example here.

After not hearing back on the issue, I contacted support who pointed me here.

Is anyone able to confirm if I’m using the driver correctly? It’s a serious concern for me that the connections increase until a new deployment.

I can’t find a definitive answer on whether I should be storing the client in memory, like I am, storing the “db” in memory, or even storing each “collection” in memory.

In contrast to the remix example, the mongo university example stores the “collection” in memory.

Any help would be greatly appreciated. Thanks.

Hey @Will_Smith1,

Welcome to the MongoDB Community!

You can refer to official MongoDB documentation as well as the MongoDB university course - Connecting to MongoDB in Node.js to learn the right approach to utilize the Nodejs driver within your application to connect to MongoDB Atlas.

May I ask what specific issues you are facing with the increased number of connections? Also, could you further clarify “connections increase until a new deployment”?

However, here the drivers maintain a connection pool, i.e., monitoring threads, rather than a single connection for all the operations, so there can be multiple connections to the cluster from a client.

It depends on your application’s use case and your desired approach for connection reuse. If your application frequently interacts with a particular database, it can be beneficial to store it in a variable and access it throughout the application. This concept extends to the client connection as well. By storing and reusing these connections, you can optimize your application’s performance and resource usage. Eventually, the decision should align with your application’s use case and requirements.

For your reference, here is example code snippet of reusing the connection from the StackOverflow response, which might be helpful to you.

Best regards,