title: Cannot read property 'collection' of null (CosmosDB+mongo+node)
body: <p>I am following this: <a href="https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-samples" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-samples</a></p>
  
  <p>here is the code : </p>
  
  <pre><code>var MongoClient = require('mongodb').MongoClient;
  var assert = require('assert');
  var ObjectId = require('mongodb').ObjectID;
  var url = 'mongodb://&lt;endpoint&gt;:&lt;`enter code `enter code here`here`password&gt;@&lt;endpoint&gt;.documents.azure.com:10255/?ssl=true';
  
  var insertDocument = function(db, callback) {
  db.collection('families').insertOne( {
          "id": "AndersenFamily",
          "lastName": "Andersen",
          "parents": [
              { "firstName": "Thomas" },
              { "firstName": "Mary Kay" }
          ],
          "children": [
              { "firstName": "John", "gender": "male", "grade": 7 }
          ],
          "pets": [
              { "givenName": "Fluffy" }
          ],
          "address": { "country": "USA", "state": "WA", "city": "Seattle" }
      }, function(err, result) {
      assert.equal(err, null);
      console.log("Inserted a document into the families collection.");
      callback();
  });
  };
  
  var findFamilies = function(db, callback) {
  var cursor =db.collection('families').find( );
  cursor.each(function(err, doc) {
      assert.equal(err, null);
      if (doc != null) {
          console.dir(doc);
      } else {
          callback();
      }
  });
  };
  
  var updateFamilies = function(db, callback) {
  db.collection('families').updateOne(
      { "lastName" : "Andersen" },
      {
          $set: { "pets": [
              { "givenName": "Fluffy" },
              { "givenName": "Rocky"}
          ] },
          $currentDate: { "lastModified": true }
      }, function(err, results) {
      console.log(results);
      callback();
  });
  };
  
  var removeFamilies = function(db, callback) {
  db.collection('families').deleteMany(
      { "lastName": "Andersen" },
      function(err, results) {
          console.log(results);
          callback();
      }
  );
  };
  
  MongoClient.connect(url, function(err, db) {
  assert.equal(null, err);
  insertDocument(db, function() {
      findFamilies(db, function() {
      updateFamilies(db, function() {
          removeFamilies(db, function() {
              db.close();
          });
      });
      });
  });
  });
  </code></pre>
  
  <p>I keep getting this Error : </p>
  
  <pre><code>db.collection('families').insertOne( {
     ^
  
  TypeError: Cannot read property 'collection' of null
  </code></pre>
  
  <p>The Database works when I test with robomongo, but won't connect with nodeJS.
  I have tried resetting the password and creating new cosmosDB from azure portal, everything seems to be alright.</p>