我具有以下数据结构:
collection/
parent_document_1/
timestamp: 0
subcollection/
document/
belongsTo: parent_document_1
data: data
parent_document_2/
timestamp: 0
subcollection/
document/
belongsTo: parent_document_1
data: data
parent_document_3/
timestamp: 0
subcollection/
document/
belongsTo: parent_document_1
data: data
我想按parent_documents
的{{1}}属性对其进行排序,然后在timestamp
集合上进行collectionGroup
查询。我不想向subcollection
添加其他属性,因为documents
下的timestamp
值是我要排序的唯一值。这样做的原因是parent_documents
可以彼此重复,并且documents
需要分别为每个timestamp
更新。
更大的情况是,我希望能够仅查询最近更新的3-5个parent_document
。
这可能与Firestore有关吗?
答案 0 :(得分:1)
除了将时间戳复制到要查询的子集合中的文档中,您别无选择。
在Firestore中,当您查询集合或集合组时,只能在这些集合的文档中立即使用字段。您不能不接触并使用其他集合中文档中的字段-这包括“父”文档和“子”文档。不同集合中的文档之间没有类似SQL的“联接”。