I need to create a Health Check for a MongoDB instance inside a Docker container.
Although I can make a workaround and use the Mongo Ping using the CLI, the best option
If you need only a simple "ping" then you can also use curl
:
curl --connect-timeout 10 --silent --show-error hostname:27017
If you get the "error" It looks like you are trying to access MongoDB over HTTP on the native driver port.
then your MongoDB is running and reply an answer.
Or use
mongo --norc --quiet --host=hostname:27017 <<< "db.getMongo()"