1

I have collection of charracters where each document has some public data like username and character level, but also a private sub collection that has things like that characters gold amount.

Right now I can query characters collection for a specific document, but sub-collection data is not returned, so I need to perform a secondary query to retrieve it.

Is this the most optimal way to achieve this or is there a way to indicate that I also want to receive sub-collection data in the first query and sort of merge them together?

Ilja
  • 44,142
  • 92
  • 275
  • 498

1 Answers1

2

Queries in Firestore are always shallow. There is no way to get documents from multiple different collection with a single query. So if you need to read from two collections, it will indeed at a minimum require two queries/read operations.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • I see, I assumed since its a sub-collection there might be some sort of "trick" / "optimisation" in place to grab its data alongside main collection. – Ilja Sep 22 '18 at 14:46
  • 1
    It's being considered, but there's lots of discussion on how it should work and the syntax. That reminds me, I think this was answered before, so I might mark as a duplicate after all. – Frank van Puffelen Sep 22 '18 at 14:50