2

im building an reporting app,

when a report sent to database its saves like

events(collection) -> New York(doc) -> Manhattan(col) -> Central Park(doc) -> event(col) -> saved documents

its basically saves, events to city to district to street to event

i fetch data of user with no problem

Stream<QuerySnapshot> tasks = FirebaseFirestore.instance
        .collection('events')
        .doc(StoredData.getCity()) //current users city information
        .collection(StoredData.getDistrict().toString()) //current users district information
        .doc(StoredData.getStreet()) //current users street information
        .collection('events')
        .where('uid', isEqualTo: FirebaseAuth.instance.currentUser?.uid) //query uid in documents uid field
        .snapshots(); 

here is my problem

i want to fetch all data of city but i cant figure out how to do that. i want to see all records of new york

B. Mercan
  • 51
  • 1
  • 9

1 Answers1

4

Firestore can only return data from a single collection at a time, or from multiple collections with the same name by using a collection group query. You can use the latter to get for example all documents from the event (singular) collections across all of your database, or under a specific path.

You can't however get the New York document and all data under it. That is simply not how the database/data model works.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807