i have mongodb model like:
data = { dataid: string, myarray:[] }
i need iterate through myarray
in api writing this
data.findone({dataid: '1234567890'}, function(err, data){ data.myarray.foreach(function(tomatch, index){ data.myarray[index].key = value; }); data.save(function(err, data){ if (err) { return res.status(500).send(err); } return res.status(200).send(data) }) });
but data not getting saved because nodejs executes data.save before end of foreach loop
i use cursor iterate on mongodb find() function, how can iterate on array in mongodb document, wait complete execution , call data.save
mongodb find returns array in case data array , data.myarray undefined can't execute data save too
Comments
Post a Comment