Skip to content
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

Sub-docs pagination works correctly but doesn't return result properties such as totalPages #230

Open
eedemir opened this issue Jan 28, 2025 · 0 comments

Comments

@eedemir
Copy link

eedemir commented Jan 28, 2025

Description
I may be the one making a mistake here but according to this library's source code and unit tests, sub-docs pagination must return not only docs but pagination results properties such as totalDocs, totalPages, prevPage etc.

In my case, normal pagination works correctly as I can see those properties but once I try to use sub-docs pagination something bizarre happens. Populated field only returns documents but those documents are not stored in "docs" property and returned field doesn't have any pagination result property. It only paginates the populated field and that is it.

Here is a example code:

let page = 1;
let limit= 10;

const option = {
      pagingOptions: {
        populate: {
          path: "products",
        },
        page: page,
        limit: limit,
      },
    };

let result = await Category.paginateSubDocs(
      { slug: req.params.slug },
      option,
    );

In above code result object returns like this:

result = {
"_id": *normal id here*
"name": "phones"
"slug": "phones"
"products": [
  {
    "_id": *normal id here*
    "name": "name"
    "price": 555
  }]
}

Like I said before pagination works in above case. If you enter another page number it returns docs that only found in that page but not any pagination result properties.

Expected behavior
Instead result object should return like this:

result = {
"_id": *normal id here*
"name": "phones"
"slug": "phones"
"products": 
  {
    "docs": *products doc array here*
    "totalDocs": 20
    "totalPages":  2
    **and rest of the pagination result properties here**
  }
}

Desktop and library versions:

  • OS: Windows 10 22H2
  • Node version: 22.13.0
  • mongoose version: 8.9.5 (Tried 8.0.0, problem still persists)
  • mongoose-paginate-v2 version: 1.9.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant