title: Mongodb function TypeError
body: <p>In the mongo shell, running the following line works fine:</p>
  
  <pre><code>director =  = 'George Lucas'
  db.movie.find( { director: director} ).sort( { title: 1 })
  </code></pre>
  
  <p>I created the following function inside the mongo shell as a test:</p>
  
  <pre><code>function bydirector(db, director) {
    db.movie.findOne( { director: director} ).sort( { title: 1 });
  }
  </code></pre>
  
  <p>Running the function with "bydirector(director)" returns the following error:</p>
  
  <p>2015-11-22T19:24:26.713-0500 E QUERY    [thread1] TypeError: db.movie is undefined :
  bydirector@(shell):1:39
  @(shell):1:1</p>
  
  <p>Any idea why it is failing?  I am passing a variable named director with the search key.</p>