android - 文档中文档的 Firebase Firestore 子集合

标签 android firebase google-cloud-firestore

在我收藏的 SnapshotListener 中,我循环访问文档:

for (DocumentChange doc : queryDocumentSnapshots.getDocumentChanges()) {
    if (doc.getType() == DocumentChange.Type.ADDED) {
        String somestr = doc.getDocument.getString("someField");
        // retrieve collection here
    }
}

在 for 循环中的每个文档中,我们称之为 doc,我在 Cloud Firestore 上有另一个文档集合。我想检索 doc 内的子集合中的所有文档(每个文档只有一个 String 字段)。我可以执行 doc.getDocument 来获取 doc 本身,我用它来获取字符串字段,但我不知道如何获取文档在其子集合中。

最佳答案

首先获取子集合:

doc.getDocument().getReference().getCollection("subcollection")

然后您像以前一样(或如 this documentation section 中所示)将文件放入其中。

关于android - 文档中文档的 Firebase Firestore 子集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50281966/

相关文章:

firebase - 是否可以从云功能访问 Firebase RemoteConfig

node.js - 将 Google People API 与 Cloud Functions for Firebase 结合使用

typescript - 无法从 Firestore 获取文档

java - Box2D - 落体在重力作用下不加速

android - AIDL 文件没有生成 Java 文件

javascript - 如何在不下载和上传数据的情况下复制具有许多记录的 Firebase child ?

google-cloud-firestore - 通过自定义对象字段查询 Google Firestore 数据库

android - DownloadManager 不适用于 android 8.0

java - Android 中网络服务器响应时间太长

flutter - 从 Firestore 获取文档时如何显示循环进度指示器