title: shell script - check mongod server is running
body: <p>I have a shell script to do some mongo db actions:</p>
  
  <p>e.g. <code>mongo testdb --eval "db.dropDatabase()"</code></p>
  
  <p>BUT, if the mongod server is not running, I get:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Is there a way in mongo I can check the connection status? Eventually I want something like:</p>
  
  <pre><code>if(mongod is running):
      mongo testdb --eval "db.dropDatabase()"
  else:
      echo "pls make sure your mongod is running"
      exit 1
  </code></pre>