When I run this code it has a Error 'TypeError: db.collection is not a function'. How to solve this problem and where is wrong in this code.
const MongoClient = require('mongodb').MongoClient;
// Connection url
const url = 'mongodb://localhost:27017/blog';
// Connect using MongoClient
MongoClient.connect(url, (err, db) => {
const note = {
text: 'Note content text',
title: 'Note title'
};
db.collection('notes').insert(note, (err, result) => {
if (err) {
console.log('An error has occurred!')
} else {
console.log('Insert success!')
}
});
});