0

i am some confuse between two choices in Firestore collection

in my Firestore i have ability to make only one main collection then make others collections as sub collections into same that main collection

now my question is this will make my main collection in big pressure ? . should i make others main collections instead of sub collections? or this will be the same ?

in other word : Will the performance of the collection which has no sub collections be better than the collection which has many sub collections? i mean per doc has sub collections .

what is the best choice ?

Mohammed Hamdan
  • 1,006
  • 5
  • 23
  • I think that this [answer](https://stackoverflow.com/questions/68662007/what-are-the-benefits-of-using-a-root-collection-in-firestore-vs-a-subcollectio) will also help. – Alex Mamo Feb 15 '23 at 06:59

1 Answers1

2

The main performance guarantee that Firestore makes is that the performance on a query depends on the amount of data it reads, not on the amount of data it has to consider.

So there is no performance difference between getting the same set of data from a smaller subcollection or getting it from one big top-level collection.


There is however a difference in write performance between the two approaches, so that is usually to pick one or the other.

Performance pressure comes from updating the indexes for each write operation, where having multiple subcollections will allow better throughput as the writes to separate subcollections are isolated from each other.

The one exception to that is when you have a collection group index, as the writes to all collections in that group will have to update the same index.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807