Reputation: 5987
I have a collection by name "trips" in Firestore. The data format is something like this
I'm trying to access documents of that Collection by using below code.
First way
try {
Firestore.instance
.collection("trips")
.where("createdByName", isEqualTo: "Suresh")
.snapshots
.listen((data) => print('Firestore response1: ${data.documents}'));
} catch (e){
print('Caught Firestore exception1');
print(e);
}
Second way
try {
Firestore.instance.collection("trips").where("createdByName", isEqualTo: "Suresh").getDocuments().then((data) {
print('Firestore response2: , ${data.documents}');
});
} catch (e){
print('Caught Firestore exception2');
print(e);
}
But, none of the above two ways is working. Don't know what I'm doing wrong.
One thing I've noticed whenever I'm removing the where("createdByName", isEqualTo: "Suresh")
part from the query it's working fine. But, the moment I include that part query is returning an empty result.
Upvotes: 2
Views: 1198
Reputation: 5987
Ok, after two days of breaking my brain for this silly thing... this is the answer to the issue... .where('trip.createdByName', isEqualTo: "Suresh")
And, the full queries are like this...
First way
Firestore.instance.collection('trips')
.where('trip.createdByName', isEqualTo: "Suresh")
.snapshots.listen(
(data){
data.documents.forEach((doc) => print( 'Firestore response1 : ${doc.data.toString()}' ));
}
);
Second way
Firestore.instance.collection("trips")
.where("trip.createdByName", isEqualTo: "Suresh")
.getDocuments().then((string) {
string.documents.forEach((doc) => print("Firestore response2: ${doc.data.toString()}" ));
});
Hope, this will be a help. :)
Upvotes: 0
Reputation: 6778
I'm not sure if the screenshot is accurate but it looks like you have a trip
node as well. That would put the hierarchy as trips.trip.createdByName
, no? If so, it's likely that the where
clause is wrong.
Upvotes: 1