There are more than 2000 objects in the rows array which need to be processed but got error Maximum call Stack exceeded.Callback function are manipulating database. I tried to use
setTimeout
that is working but making the execution slow. Is there any other method to fix it.
var updateRowsStatus = function (req, rows, next) {
if (rows.length == 0) {
return next();
}
var batchRows = rows.splice(0, 20);
var count = 0;
batchRows.forEach(function (row) {
// other function
updateSubEntity(req, row, 'rows', function (err, response) {
if (err)throw err;
if (++count == batchRows.length) {
updateRowsStatus(req, rows, next);
}
});
});
};