1
2 Comments

Data Modeling in Firestore

Hello guys, I'm currently building an app that needs a folder/file data structure

I noticed there are 3 ways of data modeling this kind of stuff in Firestore

1. Using document reference for the items of a folder
2. Embed the item itself inside the folder doc
3. Adding a subcollection to each folder

Please note that I will need all the items when querying the folder (the item won't be accessed by itself)

I'm curious about which one is the best way to do this.

  1. 1

    There is no straight solution to this but let me put my views

    Firestore is designed to handle millions of documents but each document has a limitation of 1MB.

    The limitation is definitely a problem if you are trying to store the data in a document which keeps increasing.

    Being said that, I see 2 solutions based on constraints

    1. If you can hold the items(files list) data in a 1MB in a folder document, go ahead with this as its the best efficient for storing as well as for querying.

    2. Mimic the same folder/file structure in firestore with collection/documents hierarchy and this is more scalable. But has the down side of number of reads.

    Find out how many file details you can save in 1MB if it's fits your usecase, thats the best to go. May be you can go with multiple documents per folder too which may not be quick to manage(code) but saves a lot.

    I'm not sure how your item/file details be like so can't go deep further.

    1. 1

      Awesome! Thanks for the tip :)

Trending on Indie Hackers
How I grew a side project to 100k Unique Visitors in 7 days with 0 audience 49 comments Competing with Product Hunt: a month later 33 comments Why do you hate marketing? 29 comments My Top 20 Free Tools That I Use Everyday as an Indie Hacker 16 comments $15k revenues in <4 months as a solopreneur 14 comments Use Your Product 13 comments