Answer the question
In order to leave comments, you need to log in
Pagination: how to get the number of documents found?
There was a problem with the implementation of pagination.
I need to get a figure, the total number of documents found. The problem is that I'm using for pagination limit
and skip
I get not the total number of documents, but only the numberlimit
exports.fetchArticles = (req, res, next) => {
let limit = parseInt(req.query.limit) || 10
let page = parseInt(req.query.page) || 1
Article.find({}, '-_id title content slug').sort({_id: -1}).limit(limit).skip((page - 1) * limit)
.then((articles) => {
console.log(articles.length)
return res.status(200).json(articles)
})
.catch((err) => {
return next(err)
})
}
10
?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question