How do queries work in Cloud Firestore? | Get to know Cloud Firestore #2
Why Stack Overflow recommends it
Stack Overflow users link it when explaining why Firestore rejects certain queries (multiple orderBy or range filters on different fields, != and OR) and how indexes and zig-zag merge joins make queries fast.
Recommended by 11 people across 22 different months, 2018 to 2024.
What it is
An episode of the Firebase channel's 'Get to know Cloud Firestore' series, presented by Todd Kerpelman, explaining how Firestore queries work. It covers how single-field and composite indexes work, which queries are possible, and why some, such as multiple range filters or OR queries, are not supported.
What people said
Strong rec Frank van Puffelen · 2021-08 · Stack Overflow · on “Compound query with two "orderby" clause doesn't work in Firestore, Android”
Oooh, nice! I didn't think that would be feasible here, but if it *is* that is indeed a great solution. If you'd like to learn more about why Firestore doesn't support what may at first seem like basic queries, I recommend checking Todd's excellent video on the topic: [this video]
Strong rec Frank van Puffelen · 2022-12 · Stack Overflow · on “Firestore: multiple where()'s and orderBy()”
The problem is that you can only have one so-called relational operation in Firestore, and both `.orderBy('senderId')` and `.orderBy('createdAt', descending: true)` compete for that. If you'd like to learn more about why that is, have a look at Todd's excellent video on queries in Firestore [this video] .
Recommends Todd Kerpelman · 2018-06 · Stack Overflow · on “Composite query with Orderby in firebase cloud function”
It is not. If you're doing a greater-than-or-less-than search on one field, you can't then order your results by another field. You're going to have to do the yob query first, and then sort the results afterwards. For more information, you can check out the documentation here [LINK] , or this helpful video [this video] !
Recommends creativecreatorormaybenot · 2018-09 · Stack Overflow · on “Can I filter Multiple Fields in a Firestore search?”
No , you cannot do this . Looking at the Firebase Firestore Documentation page about queries [LINK] , you will find out about the following: Cloud Firestore does not support the following types of queries: Queries with range filters on different fields, as described in the previous section. [LINK] This does not directly apply to your specific use case, but the reasoning for why your request will not work is similar: There is no index that allows you to sort according to multiple different fields. You could e.g. create indexes that sort each of the fields, but only query them individually. To understand why certain queries are not supported, you can check out this in depth explanatory video f
Recommends Renaud Tarnec · 2018-11 · Stack Overflow · on “Order by on missing field constrains result”
In a nutshell, this is because Firestore queries are based on indexes: each time you create a doc Firestore creates an index for each field of the doc. So since the field "inCanada" is only present "in a subset of the 20 documents", only this subset of documents is present in the "inCanada" index, resulting in the situation you mention. This official video from Todd Kerpelman from the Firebase team explains it very well: [this video] . (This link will open the video at 4m17s i.e. when the explanations on the index mechanism start. However the part on the impact of indexes on the querying possibilities is more around 6m22s!) If you want to include the other documents in your query results you shou
Recommends Frank van Puffelen · 2019-01 · Stack Overflow · on “Firestore "Invalid query" - Am I using Indexing wrong?”
Firestore queries can only sort or filter range on a single field. You're trying to filter on StartDate and then order on Title , which isn't possible. The Firestore documentation on queries [LINK] contains this similar example of a query that isn't allowed: Invalid : Range filter and first orderBy on different fields citiesRef.whereGreaterThan("population", 100000).orderBy("country"); Firestore only allows queries where it can meet its performance guarantees, and for ordering/range-filtering on multiple fields that is not (currently) possible. See Todd's video on Firestore queries [this video] to learn more on how this works. The typical workaround is to let Firestore handle the filter (on Start
Recommends Frank van Puffelen · 2019-03 · Stack Overflow · on “Firestore | Why do all where filters have to be on the same field?”
Cloud Firestore gives a strong performance guarantee for any read operations it allows: the time a read operation takes depends on the number of items you're reading, not on the number of items in the collection. This is a quite unique performance guarantee, since it means that your queries will take the same amount of time when you have 1 million users as when you have 1 billion users. Firestore only offers query operations for which it can maintain this performance guarantee. This is the main reason for the limitations you may find in the Firestore query API. To work around the limit, you'll typically perform the filtering, and ordering on the primary field in the query, and then sort on t
Recommends Frank van Puffelen · 2019-04 · Stack Overflow · on “Firestore not asking to create indexes but query works”
Since you're using only equalities in your query, Firestore can do a zig-zag-merge-join [LINK] based on the auto-generated single-field indexes. You can add an index on the field combination, which will typically speed up the query a bit, but it's not required. To learn more about this, have a look at How do queries work in Cloud Firestore? [this video] in the Getting to know Cloud Firestore [LINK] series.
Recommends Adrian Murray · 2019-06 · Stack Overflow · on “Get document collections in Firestore”
you would call it: db.collection('conversations').doc({docID}).collection('users') Your current query is set up to look through every conversation and then get every user in each of those. Plus the second part (getting the users) has no base document to pull from, which is why you're seeing an error. I recommend watching this video [this video]
Recommends Sukhi · 2020-02 · Stack Overflow · on “One big database versus many small databases”
Got it. Checkout FireStore (which is a NoSQL db from Firebase). You can use different Collections in the same database to separate out the data. The following link might help - [this video] Plus it has offline support.