I want to be able to compare the incoming skip value from the query parameters so that it is not greater than the total count of items in the database.
This is the code that works without the check (so it fails when skip is greater than the total):
await products
.aggregate([
{
$facet: {
paginatedResults: [
{ $match: {} },
{ $sort: sortby },
{ $skip: parseInt(req.query.skip) },
{ $limit: limit },
],
totalCount: [
{
$count: "count",
},
],
},
},
])
.then((data) => {
res.json(data);
})
.catch((error) => {
console.log(error);
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…