javascript - How to return from find in nodejs,mongoose mongodb collection -
javascript - How to return from find in nodejs,mongoose mongodb collection -
while find() element in mongodb collection, using mongoose, console.log doesn't executed in test.js
in test.js, console.log doesn't print info mongodb collection
var model = require('./model'); model.findbytag('java',function (data) { console.log(data) });
the model.js has next entry
exports.findbytag = function(tag,out) { var condtion = {"tag" : tag} tag.find(condtion,function(err,out){ // console.log(out); if (err) console.log('error returning tag!'); else { homecoming out; } }); }
when uncomment console.log file in model.js , it's log info matched in find query,
the callback in test.js file doesn't executed, did returning info model.js, wrong i'm doing ?
in model.js findbytag method returning function object instead of executing callback function . also, queried document need passed argument callback function. can modified like:
exports.findbytag = function(tag,out) { var condtion = {"tag" : tag} tag.find(condtion,function(err,doc){ // console.log(doc); if (err) console.log('error returning tag!'); else { out(doc); } }); }
javascript node.js mongodb mongoose
Comments
Post a Comment