Allow field selections in client sdk's
Let's say I have an orders collection where each document represents a customer order.
I would like to be able to fetch and listen to only the names and dates of all orders and not get the whole document.
This would speed up a lot queries where not all fields are required and save bandwidth for users.
Since selection is already present in some server side SDK's I wonder if this could be enabled with a somewhat manageable effort.
-
Weiguang Fan commented
If caching is what currently makes this feature difficult to be supported, is it possible to at least support in a query that only reads from server? Currently Firestore already supports specifying the source when reading data, also there are already some exceptions like the aggregation queries, which only work for server queried but not cache queries.
So I'm thinking that maybe we can have a query and realtime listener that is server only which can then support field selection?
-
Weiguang Fan commented
In Mobile environment, it's currently a bit of a challenge to deal with large number of documents (10s of thousands) with firestore, because the time and bandwidth required to download the entire data always is not neglectable.
Sometimes I only want to know the id and last updated timestamp of a document, so that I can do a comparison to know which documents have been outdated and then I only download the outdated document. However, with the current firestore, we'll always have to download all the complete documents.
-
Mark Breuß commented
Thanks for the thorough answer!
I can see that caching selected views would increase complexity a lot.
But from my perspective this is not really a requirement.I see it more as some sort of aggregation query since the total data sent is decreased.
In that sense I would not expect them to work offline, similar to the fact that .count() does not work for offline queries.
Long story short - i would not expect them to work offline and have a caching layer.
Although - like with every feture I would not mind if it does😉
-
Thanks for adding this feature request! 👍
The reason the Firebase client-side SDKs currently don't provide the option to get a subset of the fields of a document is that it would make the caching of documents a lot more complex. The SDKs would either have to cache multiple views/subsets of each document, which would increase memory usage, or they'd have to apply some patching strategy, which was error prone when we investigated it.
I'd love to hear your and other's thoughts on this: how (if at all) would you expect the caching layer of the client-side SDKs to deal with the multiple views?