In the case where your Atlas cluster has reached its max number of connections, you have two options.
Upgrade to a different instance type that allows more incoming connections (the preferred course of action, particularly if the higher connection count is typical for your application),
Use the Atlas
test failover
option to force an election. This button causes a new primary to be elected, and in that process, disconnects all open connections. Please note that this is not best practices to use on an ongoing basis.
Why does this happen?
Typically this problem arises when the driver for connection pooling/persistence has particularly long timeout settings for connections (as it is typically the driver that determines when a connection has gone stale).
If you require assistance to lower your connection counts regularly, please open a ticket with our technical support team.
READ MORE: For more documentation on MongoDB Atlas test failover functionality, please click here.