我在Firestore中有一个名为“trips”的集合。数据格式是这样的
我正在尝试使用以下代码访问该Collection的文档。
第一种方式
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);
}
但是,以上两种方法均无效。不知道我在做什么错。
每当我从查询中删除
where("createdByName", isEqualTo: "Suresh")
部分时,我就注意到一件事,它工作正常。但是,当我包括该零件查询的那一刻返回空结果。
最佳答案
我不确定屏幕截图是否正确,但看起来您也有一个trip
节点。那会将层次结构作为trips.trip.createdByName
,不是吗?如果是这样,则where
子句很可能是错误的。
关于firebase - Flutter Firestore插件无法结合where和isEqualTo来获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50235230/