0

I have a collection let's say "files" and a "file" document has 2 main properties (field) : name and content.
(note: I know storing files in a Firestore is not a good idea but that's just an example, let's assume the files are just text files)

When my app opens I want to be able to fetch all user's file names but not the content :

files = [{name: 'a'}, {name: 'b'}, {name: 'c'}, ...]

The reason is obvious I don't want to pull files' content unless the user explicitly ask for from the UI, minimizing the size of data being pulled from Google Cloud and reducing the cost over time.
But collection(db, 'users', user.uid, 'files') seems to return all docs data. Even worst! if one "file" document change, all the docs and their content are being pulled again from the UI onSnapshot listener...

Reading the TypeScript doc I don't see an option to do atomic selection on docs' fields. Am I missing something?

vdegenne
  • 12,272
  • 14
  • 80
  • 106
  • The client SDK cannot select fields. You can use Cloud Functions to retrieve selected data only as Admin SDK can select fields. Also, why would the listener fetch all the documents again if only 1 was changed? That seems like a problem with the implementation that you've not share in this post. – Dharmaraj Dec 22 '22 at 14:32
  • I understand your answer but I don't understand why you closed my question because my question was about "fetching all documents but partial data" not "how to fetch a subset of documents based on a query condition", therefore this duplicate flag and references are irrelevant. – vdegenne Dec 22 '22 at 14:39
  • I see all answers in the duplicates list are about "selecting some fields (partial data) from documents". Any of the questions might have code containing `where()` clause but that doesn't change the answer. Firestore client SDKs will always fetch complete documents irrespective of you are fetching all documents or querying a few. – Dharmaraj Dec 22 '22 at 14:43
  • The last link was useful ok. Thanks. – vdegenne Dec 22 '22 at 14:50

0 Answers0