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

Using limit() in count queries is ignored #8811

Open
4 tasks done
hej2010 opened this issue Nov 17, 2023 · 7 comments · May be fixed by #8812
Open
4 tasks done

Using limit() in count queries is ignored #8811

hej2010 opened this issue Nov 17, 2023 · 7 comments · May be fixed by #8812
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@hej2010
Copy link
Contributor

hej2010 commented Nov 17, 2023

New Issue Checklist

Issue Description

Using .limit(X) in a count() query is ignored.

Steps to reproduce

Run a query with .limit(X) on a collection.

Actual Outcome

The count result is the number of rows matching the query, which can be greater than the specified limit.

Expected Outcome

The count is the smallest of the number of rows and the X in .limit(X).

Environment

Server

  • Parse Server version: 6.5.0-beta.1
  • Operating system: Ubuntu 22
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): local

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: 5.3.2
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): local

Logs

Copy link

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

@matheusfrozzi
Copy link

I think that's how it's supposed to work, count the total of the query, to you know how many pages with skip/limit you can navigate.
In your case, you already know how much would be the count, the same as the limit you asked for.. and if is less, the current count would bring the correct count.

@hej2010
Copy link
Contributor Author

hej2010 commented Nov 17, 2023

I think that's how it's supposed to work, count the total of the query, to you know how many pages with skip/limit you can navigate. In your case, you already know how much would be the count, the same as the limit you asked for.. and if is less, the current count would bring the correct count.

It can still count 100k+ rows for my use case (counting a user's unread messages) when I try to limit it to 100, it's a bit unnecessary.

@mtrezza
Copy link
Member

mtrezza commented Nov 17, 2023

The MongoDB count operation supports the limit parameter, see docs. It may be more efficient than a db.collection.find(query).limit(number).count();. So I assume supporting the limit param has a use case.

@matheusfrozzi
Copy link

but if you put a limit of 100, what do you expect to be the count result?

@mtrezza mtrezza added type:feature New feature or improvement of existing feature type:bug Impaired feature or lacking behavior that is likely assumed and removed type:feature New feature or improvement of existing feature labels Nov 17, 2023
@hej2010
Copy link
Contributor Author

hej2010 commented Nov 17, 2023

A value between 0 and 100 :)

@matheusfrozzi
Copy link

I see, but as I said before, the count is to know how many times you can page it.
For example: 140 articles with a limit of 10, 14 pages.
the way you want, you don't need to count
Just get the return array and ask for the length.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants