title: How to execute mongo commands through shell scripts?
body: <p>I want to execute <code>mongo</code> commands in shell script, e.g. in a script <code>test.sh</code>:</p>
  
  <pre><code>#!/bin/sh
  mongo myDbName
  db.mycollection.findOne()
  show collections
  </code></pre>
  
  <p>When I execute this script via <code>./test.sh</code>, then the connection to MongoDB is established, but the following commands are not executed.</p>
  
  <p><strong>How to execute other commands through shell script <code>test.sh</code>?</strong></p>