TypeError: db.collection is not a function : <p>I am trying to post data to database that I have created on mLab and I am getting this error but I don't know whats going wrong.I also have read previously asked question on this topic but I am not able to solve my error as I am new to this. So here I am posting the code which I am trying to implement and It is taken from this tutorial <a href="https://medium.freecodecamp.com/building-a-simple-node-js-api-in-under-30-minutes-a07ea9e390d2" rel="noreferrer">https://medium.freecodecamp.com/building-a-simple-node-js-api-in-under-30-minutes-a07ea9e390d2</a>. </p>

<p>server.js</p>

<pre><code>const express = require('express');
const MongoClient = require('mongodb').MongoClient;
const bodyParser = require('body-parser');

const db = require('./config/db');


const app = express();

const port = 8000;

app.use(bodyParser.urlencoded({extened:true}));


MongoClient.connect(db.url,(err,database) =&gt;{

    if (err) return console.log(err)
    require('./app/routes')(app,{});
    app.listen(port,() =&gt; {
        console.log("We are live on"+port); 
    });

})
</code></pre>

<p>db.js </p>

<pre><code>module.exports = {
  url : "mongodb://JayTanna:Jay12345@ds147510.mlab.com:47510/testing"
};
</code></pre>

<p>index.js </p>

<pre><code>const noteroutes = require('./note_routes');

module.exports = function(app,db)
{
    noteroutes(app,db);

};
</code></pre>

<p>note_routes.js</p>

<pre><code>module.exports = function(app, db) {
  app.post('/notes', (req, res) =&gt; {
    const note = { text: req.body.body, title: req.body.title };
    db.collection('notes').insert(note, (err, result) =&gt; {
      if (err) { 
        res.send({ 'error': 'An error has occurred' }); 
      } else {
        res.send(result.ops[0]);
      }
    });
  });
};
</code></pre>
