0

using latest flutter version with firestore , the below is an example of my DB design , enter image description here and this , enter image description here

can collectionGroup , Get all 'hours' where 'days' document ID is equal to '2019-11-09'

coming from relational DB family this is vey simple , but am banging my head with firestore-flutter , please help me to achieve this , or should I re-design which would be lame .

sajanyamaha
  • 3,119
  • 2
  • 26
  • 44

1 Answers1

1

It's not possible to be that specific in a collection group query. A collection group query will always consider all collections with the same name. It can't be focused on a subcollection nested specifically under another collection. What you can do is query all of the document of all hours collection, and that will work no matter where it is nested. If you need to narrow that down to a specific day, the you will need to add a new field for day, and filter all the hour documents on that day.

db.collectionGroup('hours').where('day', isEqualTo: 'whatever')
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • woudnt that mean to query the whole database instead of querying just a parent document , isnt that a massive performance hit ? Apart from collectionGroup is there any other solution firestore provides ? – sajanyamaha May 12 '20 at 19:45
  • Queries on Firestore are guaranteed to have performance that only depends on the number/size of the results you get, and not dependent on the amount of data they search. In words of a team mate: when you search our haystack the performance depends on the number of needles only, and not on the size of the haystack. – Frank van Puffelen May 12 '20 at 20:00
  • @FrankvanPuffelen can you guide me to any documentation or the tech behind explaining this performance claim , cant digest , even the hay and needle story . – sajanyamaha May 12 '20 at 20:08
  • 1
    https://stackoverflow.com/questions/46603205/queries-scale-with-the-size-of-your-result-set-not-the-size-of-your-data-set – Doug Stevenson May 12 '20 at 20:32