title: How to use mongoDB with node
body: <p>When I run the script, the error returns.</p>
  
  <blockquote>
    <p><strong>TypeError</strong>: db.collection is not a function</p>
  </blockquote>
  
  <pre><code> var MongoClient = require('mongodb').MongoClient;
   var url = "mongodb://abc:12345**@xxxx.mlab.com:&amp;&amp;&amp;&amp;/myDB";
   MongoClient.connect(url, function(err, db) {
     if(err) {
        console.log(err);
     } else {
        console.log("Database created!");
        db.collection('users').aggregate([{
          '$match': {
            'organization.organizationId': "e1716c62-fdce-11e7-8be5-
             0ed5f89f718b"
          }
        },{
         "$project": {
            "deviceDetails": 1,
            "userDetails": 1
         }
       }], function(error, documents) {
             if (error) {
               console(error);
             } else {
             console.log(documents);
            }
          });
    });
  </code></pre>
  
  <p>Hi, could you please help me where am I doing wrong.Thanks! </p>