I need to call some function after finishing callback execution using Node.js and MongoDB. I am providing my code below.
var updateArr=[];
TempCollection.find({},function(err,docs){
for(var i=0;i<docs.length;i++){
if (docs[i]['login_id']=='' || docs[i]['login_id']==null) {
var zon=docs[i]['zone']+'@oditeksolutions.com';
TempCollection.findOneAndUpdate({$or:[{login_id:null},{login_id:''}]},{$set:{login_id:zon}},{new:true},function(err1,upd){
if(!err1){
updateArr.push(upd);
}
})
}
}
console.log('lrn::',updateArr.length);
if (updateArr.length > 0) {
createAllocation();
createUser();
}
})
Here I need after all documents updated both function (i.e-createAllocation and createUser
) to be called. Here before updating all document both are executing.