Home > Blockchain >  Do firestore queries with a where clause reduce network usage?
Do firestore queries with a where clause reduce network usage?

Time:01-28

When a where clause is used in Firestore is only the qualified documents sent over the network or is the whole collection sent, and where the query is applied client-side?

CodePudding user response:

Firestore queries are executed on the server, unless there is no connection to the server available, in which case they are executed against the local cache.

The query operators may be a bit more limited than what you're used to from other (especially SQL) databases, because Firestore (currently) only allows you to execute queries for which it can guarantee that the performance does not depends on the number of documents that exist in the collection, but only on the number and size of the results it returns.

I recommend reading the Firebase documentation on queries, and watching Todd's excellent Get to know Cloud Firestore series,

CodePudding user response:

Do Firestore queries with a where clause reduce network usage?

Yes, it does. When you are using a where() call, it means that you are limiting the number of documents that are returned from your query. Since you are getting fewer documents, this also means that you'll have to download less data, hence the reduced network usage.

For instance, if you have 100 documents in a collection, and you call where(), and the query only returns 5 documents, then you'll have to pay only 5 document reads and not 100.

  •  Tags:  
  • Related