我在Firestore中有一个名为“trip”的集合 . 数据格式是这样的
我正在尝试使用下面的代码访问该Collection的文档 .
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);
}
但是,以上两种方式都不起作用 . 不知道我做错了什么 .
有一件事我've noticed whenever I'从查询中删除 where("createdByName", isEqualTo: "Suresh")
部分它正常工作 . 但是,当我包含该部分查询时,返回一个空结果 .
2 回答
我不确定截图是否准确但看起来你也有一个
trip
节点 . 这会将层次结构设为trips.trip.createdByName
,不是吗?如果是这样,where
子句可能是错误的 .好吧,经过两天让我的大脑因为这个愚蠢的事情而破碎......这就是问题的答案...
.where('trip.createdByName', isEqualTo: "Suresh")
并且,完整的查询就像这样......
First way
Second way
希望,这将是一个帮助 . :)