Als het alles is of gerelateerd is aan weergave, zou paginering zoiets zijn als de onderstaande code. De code is slechts een voorbeeld:
findAll: async function (req, res) {
var responseObj = {};
try {
var responseObj = {};
var queryArray = [];
var finalAnswer = [];
var loggedinUser = mongoose.Types.ObjectId(req.user.id)
var auser = await user.findOne({ _id: loggedinUser })
var places = auser.placesUnderIt;
for (i of places) {
var singlePlaceId = mongoose.Types.ObjectId(i);
var singlePlaceData = await place.findOne({ _id: singlePlaceId })
var list = singlePlaceData.controlledStore;
for (k of list) {
finalAnswer.push(k);
}
}
queryArray.push({ _id: { $in: finalAnswer} });
var query = {
$and: queryArray
}
responseObj.count = await store.countDocuments(query);
responseObj.data = await store.find(query)
.populate('ownerId', ["firstName", "lastName", "phoneNumber", "email", "personalDetails"])
.populate('businesses')
.limit(parseInt(req.query.limit))
.skip(parseInt(req.query.skip));
var data = responseObj.data;
return res.send(responseObj);
} catch (err) {
return res.send('Error');
}
}