How to auto-reconnect to the MongoDB? C#

Hello everyone!

I’m looking for a solution to the question above: how to automatically identify that my app lost connection with MongoDB and auto-reconnect to it?

There is any event generated by the MongoDB C# library that helps with that? Or some kind of trigger to connection lost/connection failed?

Any suggestions?
Thank you!

In my experience the C# Mongo driver handles lost connections/reconnections fine. Is there something specific/more complex you are looking to do?

I was wonder if there is any event triggered correlated to a disconnection or a connection failed, so in that way, I can handle to reconnect again to my server.

I’m new at MongoDB, I don’t know if it already handle it. I couldn’t notice that on my debug and in my researches about the matter.

Can you help me?

Here is where you can read about events in the driver. The main thing you might want to watch out for is retrying a command if it fails due to a network error, but overall the driver itself handles network blips fine in my experience.

1 Like

Thank you John, I will take a look at it