title: Specify which database to use in mongodb .js script
body: <p>I just want to run a .js script against a particular mongodb database, but can't seem to get the correct syntax.</p>
  
  <pre><code>echo "print(db.address.find().limit(1));" &gt; test.js
  mongo test.js
  </code></pre>
  
  <p>How do I select the database that this will be executed on, I've tried various combinations of <code>use foo</code> with no success.</p>
  
  <pre><code>&gt; show dbs                      
  admin   (empty)
  local   (empty)
  foo 0.203125GB
  bar 0.203125GB
  </code></pre>
  
  <p>I would like to use <code>foo</code> in this case.</p>