Как получить коллекцию данных, в которой есть подколлекция в firestore?

Есть такая структура в firebase: коллекция users

Мне нужно вернуть коллекцию пользователей с адрессом при подписке на getUsers

Вот неполноценный код:

class User{
    
      String name;
      String surname;
      Address address;
    
    
      User({this.name, this.surname});
    
      Stream<List<User>> getUsers(CollectionReference firestoreInstance) {
        firestoreInstance.collection("users").getDocuments().then((querySnapshot) {
          querySnapshot.documents.forEach((result) {
            firestoreInstance
                .collection("users")
                .document(result.documentID)
                .collection("address")
                .getDocuments()
                .then((querySnapshot) {
              querySnapshot.documents.forEach((result) {
                print(result.data);
              });
            });
          });
        });
    
        //Мне нужно вернуть коллекцию пользователей с адрессом при подписке getUsers.listen((users) => ...)
    
      }
    }
    
    class Address{
      String city;
      String region;
    
      Address(this.city, this.region);
    }

Как вернуть stream c заполненными данными user?


Ответы (1 шт):

Автор решения: MiT

Snapshots вернет вам stream, а дальше выборку делать через where и тд.

Firestore.instance.collection("users").snapshots();

В данном примере получите поток, всех пользователей.

→ Ссылка