【问题标题】:How do I get list of the document ID's inside a collection without getting the content of the documents in Firestore?如何在不获取 Firestore 中文档内容的情况下获取集合中文档 ID 的列表?
【发布时间】:2020-10-23 16:55:22
【问题描述】:

我想做这样的事情:

final collectionReference = Firestore.instance.collection('myCollection');
final List<String> documentList = collectionReference.getDocList();

final query = collectionReference.orderBy('lastUpdated', descending: true).limit(100);
final List<String> documentList = query.getDocList();

目前,当我们使用get()query.getDocuments() 时,它将返回整个文档列表及其所有内容。但是您知道我们想要优化读取,因此我们利用每个文档的 1MiB 限制。因此我们不想下载整个文档的内容。相反,我们只需要 ID 用于其他用途。有没有办法做到这一点?

谢谢

【问题讨论】:

    标签: firebase flutter dart google-cloud-firestore nosql


    【解决方案1】:

    Flutter API(或任何网络或移动客户端)无法做到这一点。

    唯一的方法是使用后端代码,您可以在 Query 上使用 select()(链接到 nodejs API)之类的方法,让您选择要返回的文档字段。因此,您可以让您的应用调用后端来返回文档 ID,但不能直接在应用中。

    如果您必须从客户端查询,请考虑将查询不需要的字段移动到具有相同 ID 的另一个集合中的文档,并仅在需要时请求它们。

    【讨论】:

      猜你喜欢
      • 2023-02-25
      • 2018-04-14
      • 2019-09-24
      • 1970-01-01
      • 2018-04-04
      • 1970-01-01
      • 2020-08-01
      • 1970-01-01
      • 2022-07-08
      相关资源
      最近更新 更多