【发布时间】:2019-10-28 05:52:16
【问题描述】:
最近,我决定将我的 Firebase 数据库迁移到 Cloud Firestore。我认为这将是对Realtime database 的巨大改进,但恐怕不是。无论如何,我遇到了一种情况,我希望能够过滤文档子集合中的元素。
我的结构如下:
Mailboxes: [
{
id: vhR4bfqyo9Uqn2ONbgPv,
address: "Address 1",
packages: [
{
id: qyo9Uqn2vhR4bfqy,
value: "0011"
},
{
id: 9Uqn2qyovqyhR4bf,
value: "0022"
}
]
},
{
id: BBR4bfqyo9Uqn2ONbEpn,
address: "Address 2",
packages: [
{
id: qn2vhR4bfqyqyo9U,
value: "0066"
}
]
}
]
假设我有一个包的 value,我希望能够查看该包是否存在于 id 为 vhR4bfqyo9Uqn2ONbgPv 的邮箱中。
到目前为止,我已经尝试过以下(以及它的一些变体):
db.collection('Mailboxes').doc('vhR4bfqyo9Uqn2ONbgPv').listCollections().then(collections => {
let collRef = collections.find("id", "==", "packages");
// And, from here on, I assume I will be able to filter the items in the collection somehow.
return 0;
});
但是,我在 Firebase 云函数中收到错误消息:
TypeError: id 不是函数 在 Array.find(本机) 在 db.collection.doc.listCollections.then.collections
【问题讨论】:
-
基于 Doug 的这个回答,我认为您可能必须将您的包密钥作为数组直接复制到您的邮箱对象中:stackoverflow.com/questions/55554162/…
标签: firebase google-cloud-firestore