aravindnc / mongoose-paginate-v2

A custom pagination library for Mongoose with customizable labels.

Home Page:https://www.npmjs.com/package/mongoose-paginate-v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The hasPrevPage and prevPage returned values are not correct at page=1

serjmac opened this issue · comments

Describe the bug
The hasPrevPage and prevPage returned values are not correct at page=1.

To Reproduce
Steps to reproduce the behavior:

  1. Simple use of await Model.paginate(condition, { offset, page, limit, sort: { _id: -1 } })
  2. Returns the expected objects from the query but......
  3. But in the initial page=1, the hasPrevPage and prevPage returned values are incorrect, see below pasted log.

totalDocs: 12,
offset: 1,
limit: 20,
totalPages: 1,
page: 1,
pagingCounter: 1,
hasPrevPage: true, //should be false
hasNextPage: false,
prevPage: 1, //should be null
nextPage: null

  1. Returned values are correct from page=2 onwards.

Expected behavior
hasPrevPage and prevPage should be false and NULL when on page=1.

using mongoose-paginate-v2 1.3.13 npm install and mongoose 5.11.13

@serjmac Thanks for pointing out.

@serjmac Please update the package(v1.3.14) for the fix.

@aravindnc updated to 1.3.14, issue is fixed, that was fast.

Thank you for your work