Flutter Firestore插件无法结合where和isEqualTo来获取数据 [英] Flutter firestore plugin can't able to fetch data with combination of where and isEqualTo
问题描述
我在Firestore中有一个名为 trips的集合。数据格式如下:
I have a collection by name "trips" in Firestore. The data format is something like this
I正在尝试使用以下代码访问该收藏集的文档。
I'm trying to access documents of that Collection by using below code.
第一种方式
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);
}
第二种方式
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.
每当删除 where( createdByName,isEqualTo: Suresh)
部分运行正常。但是,当我包括该部分查询的那一刻返回空结果。
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.
推荐答案
好吧,两天后这很愚蠢的事情...这是问题的答案... .where('trip.createdByName',isEqualTo: Suresh)
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...
第一种方式
Firestore.instance.collection('trips')
.where('trip.createdByName', isEqualTo: "Suresh")
.snapshots.listen(
(data){
data.documents.forEach((doc) => print( 'Firestore response1 : ${doc.data.toString()}' ));
}
);
第二种方式
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. :)
这篇关于Flutter Firestore插件无法结合where和isEqualTo来获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!