To get total records count for pagination
diptenagile opened this issue · 1 comments
diptenagile commented
I found a solution for get total record count that would be helpful in pagination.
You will get executed query in req.quer variable . i removed options which would remove skip and limit from query after that re-applied that query.
I write following code inside the after hook.
Resource.after('get', function(req, res, next) {
delete req.quer.options; // Remove skip and limit to get total count
req.quer.count(function(err, totalRecords) { //Apply remaining query
if (err) {
console.log(err);
next();
}else {
console.log("Total records", totalRecords);
next();
}
});
});
Hope that would be helpful in pagination.
matheo commented
Thanks for this, unfortunately we cannot send headers from hooks, because Express explodes.