title: Basics of MongoDB Scripts - How to
body: <p>What are the basics of MongoDB Scripts?</p>
  
  <p>I think the script will end with <code>.js</code>, and we run it using <code>mongo try.js</code></p>
  
  <p>But if I put</p>
  
  <pre><code>print(db.foo.find())
  </code></pre>
  
  <p>in <code>try.js</code> and use <code>mongo try.js</code></p>
  
  <p>it will say</p>
  
  <pre><code>MongoDB shell version: 1.6.1
  connecting to: test
  DBQuery: test.foo -&gt; undefined
  </code></pre>
  
  <p>and if I use the interactive shell by typing <code>mongo</code> and type</p>
  
  <pre><code>&gt; db.foo.find()
  { "_id" : ObjectId("4c7a73428261000000003a7e"), "a" : 1 }
  &gt; print(db.foo.find())
  DBQuery: test.foo -&gt; undefined
  </code></pre>
  
  <p>the <code>{a : 1}</code> was something I inserted earlier using <code>db.foo.insert({a:1})</code></p>
  
  <p>what are the proper ways of doing MongoDB Scripts and how to print things out like a Ruby <code>irb</code> or Python's <code>IDLE</code>?  thanks.  (Ruby's <code>puts a.inspect</code> or <code>p a</code> can both print out the whole structure of <code>a</code> usually (all the variable names and values in <code>a</code>))</p>
  
  <p><code>alert(db.foo.find())</code> and <code>console.log(db.foo.find())</code> won't work either.</p>