title: TypeError: Cannot read property 'find' of undefined on mongoose
body: <p>I am new to MongoDB Atlas. I am trying to query the currently existing collection "dogs" in my "test2" database using mongoose. </p>
  
  <p><a href="https://i.stack.imgur.com/msGoe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/msGoe.png" alt="enter image description here"></a>  </p>
  
  <p>I am using nodeJS to perform the query</p>
  
  <pre><code>var mongoose = require('mongoose');    
  mongoose.connect('mongodb+srv://*****:*******b@cluster0-uln4x.mongodb.net/test?retryWrites=true&amp;w=majority', {
  useUnifiedTopology: true,
  useNewUrlParser: true,
  })
  .then(() =&gt; console.log('DB Connected!!!'))
  .catch(err =&gt; {
  console.log('did not work');    });    
  var db = mongoose.connection;   
  db.on('error', console.error.bind(console, 'connection error:'));
  
  db.once('open', function() {
      db.dogs.find().forEach(printjson);     //ERROR!
   });
  </code></pre>
  
  <p>Which results in the error: <code>TypeError: Cannot read property 'find' of undefined</code></p>
  
  <p>How come dogs is <code>undefined</code>?</p>