문제

We are currently storing performance and search stats from our app with a free MongoDB sandbox on MongoLab. They recently had an outage which in turn affected our app (there is no replica set on the free sandbox).

Is there anyway to check the status of a MongoDB connection quickly (without having to waiting for a timeout as this takes too long) before trying to insert or update any data?

도움이 되었습니까?

해결책

If by "detect status" you want to see whether you can access the server then use Ping:

new MongoClient("mongodb://localhost:27017").GetServer().Ping();

It throws an exception if the server cannot be reached.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top