I am new to nodejs for loop not working synchronously. Please help thanks in advance
here is my code
notifyRide:function*(body){
yield User.find({_id: {$ne: body.userId}},function(err, doc){
if(doc != null){
User.findOne({_id:body.userId},function(err, user){
Ride.findOne({_id : body.rideid},function*(err1,ride){
for (var i = 0; i < doc.length; i++) {
console.log(i)// getting 0
yield rideStatus.findOne({$and:[{receiver_id:doc[i]._id},{ride_id:body.rideid}]}, function(err, response)
{
console.log(i);//getting 1
})
}
})
})
}
})
}