I know this is for php, but I got here looking for a solution for node. Using mongoskin:
mongodb.admin().ping(function(err) {
if(err === null)
// true - you got a conntion, congratulations
else if(err.message.indexOf('failed to connect') !== -1)
// false - database isn't around
else
// actual error, do something about it
})
With other drivers, you can attempt to make a connection and if it fails, you know the mongo server's down. Mongoskin needs to actually make some call (like ping) because it connects lazily. For php, you can use the try-to-connect method. Make a script!
PHP:
$dbIsRunning = true
try {
$m = new MongoClient('localhost:27017');
} catch($e) {
$dbIsRunning = false
}