【问题标题】:How to return Firestore documents from a list of DocumentID's in a query? [duplicate]如何从查询中的 DocumentID 列表中返回 Firestore 文档? [复制]
【发布时间】:2019-08-20 08:11:44
【问题描述】:

我有一个 DocumentID 列表,我想在查询中使用它并仅返回这些文档的数据。

以下代码将返回 0 个文档:

Future<QuerySnapshot> _getGroupsList(DocumentSnapshot data) async {
List<String> _localGroupIDs = List.from(data.data['MyGroups']);

CollectionReference colRef = Firestore.instance.collection('Groups').reference();

Query query = colRef.where('id', isEqualTo: _localGroupIDs);
QuerySnapshot querySnapshot = await query.getDocuments();
return querySnapshot;
}

但是,如果我删除查询并在集合引用上运行 getDocuments(),我可以看到所有文档都可用。

我已尝试执行此处建议的操作 Is FieldPath supported in Flutter? ,但它似乎对我不起作用。我经常遇到错误。

我也在这里https://github.com/flutter/plugins/blob/master/packages/cloud_firestore/android/src/main/java/io/flutter/plugins/firebase/cloudfirestore/CloudFirestorePlugin.java 进行挖掘,我注意到 FieldPath.documentID()(第 265 行)正在使用,但无论如何我都无法访问它。

有谁知道如何使用 Flutter 和 Firestore 查询 DocumentID?

【问题讨论】:

标签: firebase flutter dart google-cloud-firestore


【解决方案1】:

var test = await Firestore.instance.collection('Note').document(id).get(); 试试这个传递你需要的文档的 id。

【讨论】:

  • 我最初是通过使用 for 循环遍历列表并按照您建议的方式获取 ID 来做到这一点的,但是对 firebase 进行大量连续调用而不是一次调用会有什么影响?代码:for(int i = 0; i &lt; _localGroupIDs.length; ++i) { DocumentSnapshot doc = await colRef.document(_localGroupIDs[i]).get(); _docs.add(doc); }
  • 为什么不获取集合并将其分配给地图数组或其他东西?
猜你喜欢
  • 2019-04-14
  • 2020-03-01
  • 2020-11-04
  • 2020-11-08
  • 1970-01-01
  • 2020-11-22
  • 2021-05-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多