In the mongo shell, running the following line works fine:

```
director =  = 'George Lucas'
db.movie.find( { director: director} ).sort( { title: 1 })

```

I created the following function inside the mongo shell as a test:

```
function bydirector(db, director) {
  db.movie.findOne( { director: director} ).sort( { title: 1 });
}

```

Running the function with "bydirector(director)" returns the following error:

2015-11-22T19:24:26.713-0500 E QUERY [thread1] TypeError: db.movie is undefined :
bydirector@(shell):1:39
@(shell):1:1

Any idea why it is failing? I am passing a variable named director with the search key.