Currently my application uses MongoDB. If I send a request while mongo is not running it will wait 30 seconds before returning a Timeout Error. Is there a way that I can catch this while starting up my application?
Is there a way to verify that mongodb is running in Java?
226 views Asked by bcgilmartin At
2
There are 2 answers
0
On
You can:
- Reduce the server selection timeout. See here for relevant development and production configuration guidance.
- Create another client with a low server selection timeout (e.g. 1) and perform a ping (issue
{ping:1}
using run command helper). This way you'll know within 1 second whether the deployment is up & running.
Ended up going with pinging the Socket:
This will throw an error if mongo is not connected