title: Using Mongodb: TypeError: Cannot read property 'collection' of undefined
body: <p>Ran in to this problem while doing <a href="https://www.freecodecamp.com/challenges/store-data-in-mongodb" rel="nofollow noreferrer">https://www.freecodecamp.com/challenges/store-data-in-mongodb</a></p>
  
  <p>error message was</p>
  
  <pre><code>swyx:~/workspace $ learnyoumongo run find.js
  /home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/mongodb/lib/server.js:231
          process.nextTick(function() { throw err; })
                                        ^
  
  TypeError: Cannot read property 'collection' of undefined
      at Exercise.&lt;anonymous&gt; (/home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/exercises/find/exercise.js:37:5)
      at next (/home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/exercise.js:271:17)
      at Exercise.end (/home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/exercise.js:277:5)
      at Workshopper.end (/home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/workshopper/workshopper.js:191:12)
      at Workshopper.done (/home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/workshopper/workshopper.js:323:19)
      at Exercise.&lt;anonymous&gt; (/home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/exercise.js:160:14)
      at /home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/workshopper-exercise/exercise.js:147:16
      at /home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/exercises/find/exercise.js:20:21
      at /home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/mongodb/lib/mongo_client.js:238:20
      at /home/ubuntu/.nvm/versions/node/v4.6.1/lib/node_modules/learnyoumongo/node_modules/mongodb/lib/db.js:242:14
  </code></pre>
  
  <p>there are other similar question on here but none of them were describing this exact problem</p>
  
  <p>for reference this was the (valid) code i was running it on</p>
  
  <pre><code>var mongo = require('mongodb').MongoClient
  var age = process.argv[2]
  
  var url = 'mongodb://localhost:27017/learnyoumongo'
  
  mongo.connect(url, function(err, db) {
    if (err) throw err
    var parrots = db.collection('parrots')
    parrots.find({
      age: {
        $gt: +age
      }
    }).toArray(function(err, docs) {
      if (err) throw err
      console.log(docs)
      db.close()
    })
  })
  </code></pre>