【发布时间】:2021-08-18 10:35:09
【问题描述】:
我可以使用 List<String> 搜索 Firestore DocumentID 吗?
我正在尝试使用列表中的一些 documentID 选择来搜索我的收藏。该列表将由几个字符串组成。我可以使用它搜索 Firestore 集合吗?
这是列表:
List<String> _selectedBusStop = List<String>();
这是我根据此处的列表查找 DocumentID 时使用的代码。
Future <void> saveRoute(_selectedBusStop) async{
Firestore.instance.collection('markers').where('BusstopName', isEqualTo: _selectedBusStop)
.snapshots().listen((location) {
if(location.documents.isNotEmpty){
for (int i = 0; i < location.documents.length; i++){
initRoute(location.documents[i].data, location.documents[i]);
}
}
});
setState(() {
});
}
我正在使用where 和isEqualTo 还是这种方法有误?知道如何使它适用于这部分吗?提前感谢您的帮助。
List 有一些BusstopName,但不是全部。我不想只从 List 中检索 Firestore 中的所有数据。很抱歉造成这么多误会。
【问题讨论】:
-
这段代码是否有效?如果没有,您收到的错误消息是什么?还要澄清一下,
_selectedBusStop是 documentId 还是文档中字段BusstopName的内容? -
您是否需要
BusstopName(数组字段)与_selectedBusStopList 完全相同的文档,或者该数组包含来自_selectedBusStop的任何值? -
如果它是一个documentId,你可以异步地向
collection("markers").doc("yourDocumentId")发出请求,然后只过滤掉实际存在的documentSnacpshots。 (您可以调用 DocumentSnapshot.exists)。您需要检查 flutter firestore sdk 文档以获得正确的语法。 -
_selectedBusStop是 DocumentID 以及文档中的数据之一。抱歉没有说清楚。 @托马斯 -
实际上
BusstopName不是一个数组字段,它只是一个String。 DocumentID 的名称实际上与文档中的BusstopName相同。我会更新我的问题。很抱歉造成这么多的误会。
标签: flutter google-cloud-firestore