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

TotalDocs returning 0 while there is result #39

Closed
yuqing630 opened this issue Aug 13, 2019 · 9 comments
Closed

TotalDocs returning 0 while there is result #39

yuqing630 opened this issue Aug 13, 2019 · 9 comments
Assignees

Comments

@yuqing630
Copy link

    when trying to run this 

somthing.paginate(filters, options, (error, result) => {
if (error) {
errorHandler(res, error);
} else {
res.status(statuses("ok")).send({
result.docs,
result.totalDocs
});
}

option={ populate: [ 'images' ],
sort: { 'date.created': 'desc' },
limit: 100,
offset: 0 }

mongoose version
"mongoose": "~5.6.9",
"mongoose-paginate-v2": "^1.3.0",

Screen Shot 2019-08-13 at 3 36 38 PM

as you can see from the screen shot they are returning 2 result but the total docs 0

@aravindnc aravindnc self-assigned this Aug 14, 2019
@aravindnc
Copy link
Owner

@yuqing630 Can you share the query used in filters.

The format is: Model.paginate([query], [options], [callback])

@yuqing630
Copy link
Author

yuqing630 commented Aug 14, 2019

 "filters": {
                    "id": {"$in": ["0123456789abcdef01234567", "1123456789abcdef01234567"]},
                    "product": { "$in": ["4839"]}
                },

@aravindnc
Copy link
Owner

@yuqing630 Can you try this in the new version.

@yuqing630
Copy link
Author

ok will do

@ingvarr6
Copy link

ingvarr6 commented Oct 17, 2019

Hi @aravindnc. I ran into a similar problem. If in the option add

collation: {
  locale: 'en_US',
  numericOrdering: true
}

My query looks like this:
{'price.forsale': {'$gte': '0', '$lte': '1000000'}}

then the number of documents is calculated incorrectly, it seems that because when the counting of the found documents is in progress, the collation does not apply

const countPromise = this.find(query).exec();

The idea should be like this:
const countPromise = this.find(query).collation(collation).exec();

@aravindnc
Copy link
Owner

@ingvarr6 I've just tested with 1,00,000 rows of data and it is working fine with v1.3.1.
I'm correctly getting the totalDocs count.

@aravindnc
Copy link
Owner

@ingvarr6 I've added collation to the new version. Thanks for pointing out.

@aravindnc
Copy link
Owner

@yuqing630 @ingvarr6 Please feel to reopen this thread if the issue exists.

@lingo
Copy link

lingo commented Feb 18, 2021

I'm seeing the same problem as @ingvarr6 with version 1.3.14. When I ensured the collation is applied before the count call, then the results are correct. Otherwise, I get 0 results.

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

4 participants