Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore group collection query using Flutter

I am new in Firestore database. I am using an app using flutter and Firestore. The database structure for my app is like that:

Rooms --Room1-----Reservations.....reservation dates
                              .....reservation dates
        Room2-----Reservations.....reservation dates
        Room3
        Room4-----Reservations.....reservation dates
        Room5-----Reservations.....reservation dates
                              .....reservation dates
                              .....reservation dates

'Rooms' is level 1 collection which holds all the room details. Each of the room data holds the 'Reservations' collection to holds all reservation details(check_in and check_out date) for that room. Now I want to get the list of rooms which are available in a specific date span. How to work with 'group collection query' for this requirement? Or it is possible to do the same by 'group collection query'?

like image 473
dev_android Avatar asked Apr 14 '26 15:04

dev_android


1 Answers

Late but, if anyone comes back to this, now in firestore there is something called collectionGroup query where you can get all subcollections if they have same name. Which can be done as

Firestore.instance.collectionGroup('Reservations').getDocuments()

This will give you the list of all the Reservations across all rooms. Please read in detail about collection group query here in the documentation

like image 118
dlohani Avatar answered Apr 16 '26 05:04

dlohani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!