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

Firestore Count() query #353

Closed
spyr0s opened this issue Aug 12, 2023 · 6 comments
Closed

Firestore Count() query #353

spyr0s opened this issue Aug 12, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@spyr0s
Copy link

spyr0s commented Aug 12, 2023

Is your feature request related to a problem? Please describe.
I have a problem when I want to get a count of documents of a specific condition
For example get the players that have a score > 10.000, or that signed in after a specific date etc

Describe the solution you'd like
Support the count query of firestore

Describe alternatives you've considered
No alternatives, getting all the documents paginated and count them is out of the question

@spyr0s spyr0s added the enhancement New feature or request label Aug 12, 2023
@BearDooks
Copy link
Member

@spyr0s if you run the query and store the result, can't you just run the size option on the array?

Example

var query: FirestoreQuery = FirestoreQuery.new()
query.from("players")
query.where("chipgamehandicap", FirestoreQuery.OPERATOR.GREATER_THAN, 4)
var result: Array = yield(Firebase.Firestore.query(query), "result_query")
print(result.size())

Or am I way off mark here?

@WolfgangSenff
Copy link
Collaborator

@BearDooks - you should be right, but it might be weird with timing and stuff where it'll not be atomic I guess. I'll have to look into this closer, and am going to do so today while I work on the Firestore huge refactor!

@nicolagianelli
Copy link

nicolagianelli commented Jul 5, 2024

@WolfgangSenff - It isn't the same, with query and size you will be charged by every document read, instead with count you will be charged 1 read every 1000*index documents.
I'm interested in this implementation (count/sum/average aggregations).
Thank you for this library!

@WolfgangSenff
Copy link
Collaborator

WolfgangSenff commented Jul 5, 2024

@WolfgangSenff - It isn't the same, with query and size you will be charged by every document read, instead with count you will be charged 1 read every 1000*index documents. I would be interested in this implementation(count/sum/average aggregations). Thank you for this library!

Ah, interesting, okay, good point! I will eventually look into it, but just lost my job last week so am looking for a new job now. If you want to support the project and get the implementation sooner, that would be incredibly helpful. We do now support commits, which make atomic updates much cheaper! But it's obviously not the same. I'll post updates about it at https://patreon.com/KyleSzklenski.

Edit: Dang. Looking over the query stuff again, I'm tempted to rewrite the entire thing there as well. :/ It would be so much work, but looking at the code, it's more or less completely unmaintainable at this point, no way to add new stuff without breaking the old.

@WolfgangSenff
Copy link
Collaborator

Alright, had a chance to dig into this, and it seems like it can be fixed without a rewrite. I will try to get to it within the next couple months I guess, if I can find a job that would be even better.

@WolfgangSenff
Copy link
Collaborator

I've added the appropriate changes, but have not yet made a release. Never the less, I'm closing this for the time being. I'll release it when I have more time available. Fixed in #420

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants