Basically what you are saying, is that you have the following structure:
Tier-1 (collection) -> docId(document) -> Tier-2 (collection) -> docId(document) -> Tier-3 (collection) -> docId(document)
You can do the following:
void getData() {
Firestore.instance
.collection("Tier-1")
.where("name", isEqualTo: "peter")
.getDocuments()
.then((querySnapshot) {
querySnapshot.documents.forEach((result) {
if (result.exists) {
print(result.data);
} else {
Firestore.instance
.collectionGroup("Tier-2")
.where("name", isEqualTo: "peter")
.getDocuments()
.then((querySnapshot) {
querySnapshot.documents.forEach((result) {
if (result.exists) {
print(result.data);
} else {
Firestore.instance
.collectionGroup("Tier-3")
.where("name", isEqualTo: "peter")
.getDocuments()
.then((querySnapshot) {
querySnapshot.documents.forEach((result) {
if (result.exists) {
print(result.data);
} else {}
});
});
}
});
});
}
});
});
}
First you check the top collection Tier-1
, if it returns no result, then you need to check the subcollection Tier-2