I've been doing some research within these couple of days but got stuck while trying to test the codes that I got from the web.
var MongoClient = require('mongodb').MongoClient,
format = require('util').format;
MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) {
if (err) {
throw err;
} else {
console.log("successfully connected to the database");
db.collection('chat', function(err, collection) {
collection.find({}, {
tailable: true,
awaitdata: true,
numberOfRetries: -1
})
.sort({
$natural: 1
})
.each(function(err, doc) {
console.log(doc);
})
});
}
db.close();
});
And the error is: c:\Project\node_modules\mongodb\lib\mongo_client.js:406 throw err ^ Am I missing any external library/reference because the error says "Cannot read property 'find' of undefined".
mongodb version: "2.0.31"
err
before accessingcollection
. – Sirko