Reputation: 327
I have a large collection of documents on Cloud Firestore, and each document is quite big too. I need to download them all to the front-end application, to only read one attribute from each (location).
Retrieving all the documents would use a lot of bandwidth, and computers with a slow internet connection would take 10-30 seconds to download. I need this to be done quicker, so I was thinking of using a SELECT query, to get only the location attribute, but my question is: Is the whole document information still downloaded to the front end and then slice-off the unwanted attributes, or am I only getting from the backend only the location.
If the later was the case, then the time it takes to get all documents would be less, as each document size would be a lot smaller (as only location is retrieved). Could anyone confirm how that works?
If anyone has any other ideas of how to approach this, it would be great.
Thanks,
Carlino
Upvotes: 0
Views: 118
Reputation: 138814
Is the whole document information still downloaded to the front end and then slice-off the unwanted attributes, or am I only getting from the backend only the location.
Yes, it is downloaded the entire document but it is not sliced in any way. Cloud Firestore listeners fire on the document level. There is no way to get triggered with just particular fields in a document or split the document to get only one property. It's the entire document, or nothing. So the Firestore client-side SDKs always returns complete documents. Unfortunately, there is no way to request only a part of the document with the client-side SDK, although this option does exist in the server-side SDK's select() method.
If the later was the case, then the time it takes to get all documents would be less, as each document size would be a lot smaller (as only location is retrieved). Could anyone confirm how that works?
It is not the case since you cannot get only a single property of a document.
If anyone has any other ideas of how to approach this, it would be great.
The common approach in this case is to denormalize the data. This means that you should create a new collection in which you should store the same documents but those document will only contain one property. In this case the size of a document will be very small.
Upvotes: 1