mongodb - shell script - check mongod server is running -


i have shell script mongo db actions:

e.g. mongo testdb --eval "db.dropdatabase()"

but, if mongod server not running, get:

mongodb shell version: 2.0.4 connecting to: testdb tue may 14 04:33:58 error: couldn't connect server 127.0.0.1 shell/mongo.js:84 

is there way in mongo can check connection status? want like:

if(mongod running):     mongo testdb --eval "db.dropdatabase()" else:     echo "pls make sure mongod running"     exit 1 

you should able create bash script this:

mongo --eval "db.stats()"  # simple harmless command of sort  result=$?   # returns 0 if mongo eval succeeds  if [ $result -ne 0 ];     echo "mongodb not running"     exit 1 else     echo "mongodb running!" fi 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -