-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
How to declare a query in the Collection options? #11
Comments
Hi Thijs. Currently you can pass in a Firestore Query object to the constructor. However, this is a somewhat cumbersome and verbose API and I have therefore not promoted it too much. It works like this: const query = firebase().firestore().collection('albums').where('name', '>=', 'D');
const col = new Collection('albums', {
query: query
}); I am however currently working on a new Query API which will solve this (amongst other things). const col = new Collection('albums');
col.query = col.ref.limit(10); |
Yes, that seems really too verbose. And since you're referencing the album collection twice, it even feels wrong to me. Wouldn't it be convenient to make the options.query a function which is passed the collection reference? Since that is what the query is built on. Something like this could work I think: const col = new Collection('albums', {
query: ref => ref.where('name', '>=', 'D')
}); |
Hey that's actually a really elegant solution, I hadn't considered that one, nice! I'll take it into consideration when I continue work on the Query API. |
Hey, I've finished work on the new query API & docs. I've taken your suggestion as I found it very elegant. This is how it will work: Let me know in case you have any feedback on this. |
Awesome! That was quick 😄 I don't have any more feedback. It's looking good 👍 |
Thanks! |
Hi @IjzerenHein I was trying out this API today but ran into a problem: public pendingUserRegistrations = new Collection("userRegistrations", {
query: ref =>
ref
.where("status", "==", UserRegistrationStatus.PendingApproval)
.orderBy("updatedAt", "asc")
.limit(100),
}); Here I am getting an error:
To solve this I am now doing it the old-school way: public pendingUserRegistrations = new FsCollection("userRegistrations");
constructor() {
const col = this.pendingUserRegistrations;
col.query = col.ref
.where("status", "==", UserRegistrationStatus.PendingApproval)
.orderBy("updatedAt", "asc")
.limit(100);
} Could it be that I am missing something? |
Hey Thijs. Hmm that's strange, that should have worked. Just so be sure, are you using v0.11 of firestorter? |
Somehow my version was still stuck on 0.10. I thought 0.11 would show up in It seems to work now! 👍 |
Sweet! |
The docs claim that
query
is part of the options argument of the Collection constructor, but don't mention how to declare it. The only examples I found set the query on the already created collection reference like so:How would you pass this query as part of the options?
The text was updated successfully, but these errors were encountered: