title: Error: Cannot read property 'close' of null
body: <p>hello dear community im wondering myself why i get this error when i try to use mongodb and nodejs.</p>
  
  <pre><code>const MongoClient = require('mongodb').MongoClient;
  MongoClient.connect('mongodb://localhost:27017/TodoApp', (err, db) =&gt; {
      if (err) {
          console.log('Unable to connect to MongoDB server.')
      }else{
          console.log('Connected to MongoDB server.')
      }
      db.close();
  });
  </code></pre>
  
  <p>Output in the <strong>console</strong>:</p>
  
  <blockquote>
    <p>Unable to connect to MongoDB server.
    C:\Users\eljubec\Desktop\node-todo-api\node_modules\mongodb\lib\mongo_client.js:421
              throw err
              ^</p>
    
    <p>TypeError: Cannot read property 'close' of null
        at MongoClient.connect (C:\Users\eljubec\Desktop\node-todo-api\playground\mongodb-connect.js:9:8)
        at connectCallback (C:\Users\eljubec\Desktop\node-todo-api\node_modules\mongodb\lib\mongo_client.js:527:5)
        at C:\Users\eljubec\Desktop\node-todo-api\node_modules\mongodb\lib\mongo_client.js:418:11
        at process._tickCallback (internal/process/next_tick.js:150:11)</p>
  </blockquote>