Friday 15 August 2014

node.js - nodejs, mongodb-update, async, callback is not consider as a function -



node.js - nodejs, mongodb-update, async, callback is not consider as a function -

i have problem code below. goes fine, until db.collection.update.

at @ console.log(n.6), callback not consider function anymore. , don't understand why.

the console display: callback(errorcode404) typeerror: object not function

var newdata = req.body; ... async.waterfall([ function(callback){ console.log('n3'); db.getconnection(callback); }, function(db, callback){ console.log('n4'); db.collection('dossiers', callback); }, function(dossiers, callback){ console.log('n5'); dossiers.update({'_id': mongodb.objectid(id)}, {$set:newdata}, callback); }, function(result, callback){ console.log('n6'); if(result != 1) { console.log('n6.1'); callback(errorcode404); } console.log('n6.2'); callback(null, 'dossier mise jour.'); } ], function(err, result){ ... });

can clarify me this?

what's happening update callback has 3 parameters: error (if any), count of records modified, , status object. waterfall handles error parameter, lastly 2 passed parameters subsequent waterfall function (n6), callback beingness provided third parameter, not second.

so need alter part of code like:

... function(dossiers, callback){ console.log('n5'); dossiers.update({'_id': mongodb.objectid(id)}, {$set:newdata}, callback); }, function(nummodified, status, callback){ console.log('n6'); ...

node.js mongodb asynchronous express asynccallback

No comments:

Post a Comment