-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add pagination to an API endpoint? #67
Comments
Edit December 4 2020: Here is a blog post that I wrote with detailed information about it Pagination in nodejs with mongoHello! Start by accepting (and sending) these new query parameters on your API
For example, you want 20 elements per page, you have to call the API like this: First Page axios.get(`myapi.com/api/users?limit=20&skip=0` Second page axios.get(`myapi.com/api/users?limit=20&skip=20`) Just send on skip the current page number minus 1 times page size axios.get(`myapi.com/api/users?limit=${PageSize}&skip=${ (CurrentPage-1) * PageSize }`) Now, back on the server side route.get('/api/users', (req, res)=> {
const limit = parseInt(req.query.limit);
const skip = parseInt(req.query.skip);
MyMongooseModel.find({ }).skip(skip).limit(limit).exec()
}) |
i have made a helper function for pagination and search filter with sorting .... const listData = async (doc, filter) => {
} |
Hi @santiq,
How can I add pagination to mongoose models?
The text was updated successfully, but these errors were encountered: