1

I have deep nested collection and sub collections. I am just worry about peformance

Will affect deep nested collections and sub collections on peformance?

Here is deep nested collections and sub collections:

db.collection("col1/doc1/col2/doc2/col3/doc3/col4").doc(doc4).set(data);

Or it will be faster to separate them like bellow:

db.collection("col1/doc1/col2").doc(doc2).set(data);
// and
db.collection("col3/doc3/col4").doc(doc4).set(data);

Now which of them are faster and peformant?

Muhammad
  • 2,572
  • 4
  • 24
  • 46

1 Answers1

6

There should be no difference at all. Each collection and subcollection, no matter the depth, should operate completely independently of each other. The collection is simply identified by its path, which is just a string.

The primary performance characteristic of Firestore is that queries scale with the size of the result set, not the size of the collection. So you can have massively huge collections, but that will not impact the performance of your query. It stands to reason that adding a few extra components to the path of a collection does not affect performance at all.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441