majestiq
majestiq

Reputation: 565

firebase Deep collectionGroup query in firestore

I have a collection structure in Firestore that looks like:

/teams/**/days/**/milestones/**
/teams/1WCraAZXLSNSoMvkZuSV/days/20210822/milestones/xyzdocid

So, I would have a set of documents in the milestones collection at the end. I'm trying to query milestones as a collectiongroup. How do I setup a collectionGroup index for this?

Is this too deep for the collectionGroup to work? What does the index look like for this? Is it possbile to create this collectionGroup index in the firebase emulator?

Upvotes: 0

Views: 299

Answers (1)

majestiq
majestiq

Reputation: 565

To anybody running into this same problem:

  1. In the Emulator, collectionGroups and all index related operations automatically work. You don't need to setup anything special. This wasn't very well documented. I spent quite some time trying to find out how to create an index in the emulator. This also means, that you will need to do quite a bit of testing with a live firebase account, because most things will not automatically work there.

  2. The collectionGroup format is based on the name of the collection only and not your indexes or any kind of paths. Meaning, if you have collections called "milestones" anywhere in your structure, the collectionGroup concept will combine them together. This is very powerful, but be careful about collections / subCollections with the same name but different purpose.

Upvotes: 1

Related Questions