Search code examples
mongodbconnection-poolingmongodb-atlas

MongoDB Atlas: High number of connections alert


I have a small MongoDB Atlas cluster with a limit of 100 connections. The dashboard is showing me an alert for the number of connections but I only have a couple of connected clients.

What is the reason for the high number of connections?


Solution

  • First, make sure that your client applications are sharing the same driver client instance. Make it a singleton and reuse it, don't instantiate new clients on every request.

    Next, configure the max connection pool size. The max connection count on an M2 cluster is 100 and the default for the connection pool size is 100.

    You can override the value in code or directly in the connection string using the following syntax

    mongodb+srv://user:password@...?&retryWrites=true&w=majority&maxPoolSize=10