mongodb - Node.js:Typeerror cannot read property 'find' of undefined -
i've been doing research within these couple of days got stuck while trying test codes got 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 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 error is: c:\project\node_modules\mongodb\lib\mongo_client.js:406 throw err ^ missing external library/reference because error says "cannot read property 'find' of undefined".
mongodb version: "2.0.31"
you check possible error in first callback, not second one. instead of
db.collection('chat', function(err, collection) { collection.find({}, {...
try:
db.collection('chat', function(err, collection) { if (err) { throw err; } else { collection.find({}, {...
this won't make code snippet want, let find out error preventing working.
Comments
Post a Comment