title: mongoDB node.js findAndModify troubles
body: <p>I am doing an online course  about MongoDB which is unfortunately a little out of date.  It seems some of the functions have changed (course is using version 1.4 while I am using 3.0.)</p>
  
  <p>Here is the code I am having trouble with, which I have tried to bring up to date with the current version of MongoDB:</p>
  
  <h2>app.js</h2>
  
  <pre><code>var MongoClient = require('mongodb').MongoClient;
  
  MongoClient.connect('mongodb://localhost:27017/course', function(err, db) {
  if (err) throw err;
  
  db.collection['counters'].findAndModify({
      query: {
          name: 'comments'
      },
      update: {
          $inc: {
              counter: 1
          }
      },
      new: true
  }, function(err, doc) {
      if (err) throw err;
  
      if (!doc) {
          console.dir('No counter found for comments.');
      } else {
          console.dir('Number of comments: ' + doc.counter);
      }
  
      return db.close();
  });
  });
  </code></pre>
  
  <p>If I run the same findAndModify through the Mongo shell I get the anticipated result (increment the counter and display the new document,) but when I run this with node it has no effect on the database and throws this error:</p>
  
  <pre><code>TypeError: Cannot call method 'findAndModify' of undefined
  </code></pre>
  
  <p>Any tips?</p>