Reputation: 1476
So I have a document in this form:
Field:
NestedField: Value
How can I use the where()
method in Flutter to fetch all documents that satisfy a condition on NestedField
? I.e:
Firestore.collection("forms").where("Field.NestedField",isEqualsTo: "Op1").getDocuments(). // This returns null
Upvotes: 3
Views: 4954
Reputation: 1476
Alright, so this was caused by another error with no relation to Firestore directly. The Field.NesterForm
approach works and it returns the data. Since Firestore uses JSON then it's the correct way to access nested fields this way. The code I was testing with was:
List<DocumentSnapshot> docs;
await Firestore.instance.collection('form')
..where("FirstForm.Operator",isEqualTo: _filter.text)
.getDocuments().then((query) {
docs = query.documents;
});
print("DOCS: $docs");
The ..
before the where()
that I didn't see at first caused the await
to not actually wait for the return so the print of my docs variable always returned null. Once I removed one dot, it works fine now and the equals is working.
Upvotes: 2