MongoDB on Node.js doesn't work, it returns undefined -
in following code:
var mongoclient = require('mongodb').mongoclient; mongoclient.connect('mongodb://localhost:27017/db_name', function(err, db){ if (err) throw err; var collection = db.collection('col_name'); console.log(collection.find().toarray(function(err, items){})); }); when run above, doesn't return results , instead returns undefined. missing?
also, in order confirm there exist collections on db, there are, tried add console.log(db.getcollectionnames());, looks has no such method in node.js driver. still possible confirm existence of collections? (anyway want use debug in these situations - don't need method though).
thanks.
don't log entire find() function, checking in callback:
collection.find().toarray(function(err, items){ console.log(items); });
Comments
Post a Comment