I have a shell script to do some mongo db actions:
e.g. mongo testdb --eval "db.dropDatabase()"
BUT, if the mongod server is not running, I get:
MongoDB shell version: 2.0.4
connecting to: testdb
Tue May 14 04:33:58 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
Is there a way in mongo I can check the connection status? Eventually I want something like:
if(mongod is running):
mongo testdb --eval "db.dropDatabase()"
else:
echo "pls make sure your mongod is running"
exit 1
try running this in your shell script:-
If the value is numeric you know that the process is running, if you get an empty value, flag it as service not running...
You should be able to create a bash script like this:
this is what i run to check if mongod is up: