我不知道您的平台是什么,但访问子集合只是定义该集合的路径。
例如,如果您想访问受让人子集合,则可以这样定义路径(Swift,但跨平台的概念是相同的)
let tasksCollectionRef = self.db.collection("Tasks")
let taskDocRef = collectionRef.document("some task id")
let assigneesSubCollectionRef = userDoc.collection("assignees")
assigneesSubCollectionRef(completion: { documentSnapshot, error in
//do somethingn with the documents within assignees
我不想为每个任务执行“[taskId]/assignees”提取。
因此,您可以使用这种代码流在代码中处理它
iterate over tasks
read the assignees collection for each task
或者您可以更改模型并将受让人存储在每个任务中。您可以使用数组,甚至是地图来包含受让人
task_id //document
assignees //map
assignee_0 //map
name //field
assignee_1 //map
name //field
当任务文档被读取时,被分配者将是一个可以读取的字段。在这里,我将assignees 字段读入字典数组并对其进行迭代
let assignees = doc.get("assignees") as! [String: Any]
for a in assignees {
print(a.key, a.value)
}