Why do I need to restart my MongoDB primary every night to prevent it from slowing down?

Hi,

I’m experiencing an issue with my MongoDB primary where it becomes slow every morning unless I restart it nightly. I’ve set up monitoring, and I can see timeouts occurring when this slowdown happens. While trying to find the root cause, I noticed that the value for awaitingTopologyChanges is quite high and continues to rise, eventually reaching close to 1 million by the end of the day.

The only way to bring this value down is by restarting the primary. Initially, I suspected it could be a connection leak, but the number of active connections doesn’t seem unusually high, and it remains stable even when the primary is restarted. After the restart, the primary runs smoothly, and I no longer see slow queries or replication lag to secondaries.

In summary:

•	The awaitingTopologyChanges value steadily increases throughout the day.
•	Restarting the primary temporarily resolves the slowdown.
•	I don’t see significant changes in active connections before or after the restart.

What could be causing this increasing awaitingTopologyChanges value, and how can I investigate the root cause further? Any insights or suggestions would be greatly appreciated.

Thanks!