【发布时间】:2022-01-15 10:23:40
【问题描述】:
我正在将 Cloud Firestore 与 Flutter 结合使用,并向礼品购买者展示产品以供礼品接收者使用。
我想向 giftBuyers 推荐 giftRecipients 的大量产品。因为 products 的列表很大,我想避免将它复制到每个 giftBuyer 的每个 giftRecipient。
我希望 products 只向给定 giftRecipient 的 giftBuyer 显示一次。但是,我希望将来能够搜索 giftBuyer 为 giftRecipient 查看的所有 产品。
我开始使用的架构是:
- 产品
- 产品1
- 商家名称
- 产品名称
- giftBuyerCollection
- 礼物买家 A
- giftRecipients
- 礼物收件人 X
- productViewed: true
- giftRecipient Y
- 礼物买家 B
- giftRecipients
- giftRecipient X
- giftRecipient Y
- 产品1
当我获取产品时,我想创建一个查询
pseudocode{
return all product documents where
.collection(giftBuyerCollection)
.doc(giftBuyer A)
.collection(giftRecipients)
.doc(giftRecipient X)
.field(productViewed does not exist)
}
这可能吗?如果是这样,它会涉及多个查询吗?这似乎是 collectionGroup 的用例,但我不确定如何使用 ID 来构建它。
我考虑的另一个替代模式是
- 产品
- 产品1
- 商家名称
- 产品名称
- giftBuyer A-giftRecipient X:真
- giftBuyer A-giftRecipient Y: true
- 产品2
- 商家名称
- 产品名称
- giftBuyer B-giftRecipient X:真
- giftBuyer B-giftRecipient Y: true
- 产品1
使用where() 方法会更好,但对于安全规则来说似乎是不可能的。
欢迎提供其他架构建议。
这些提要和聊天建议似乎不适合我的用例。
Firebase Firestore Structure for getting un-seen trending posts - Social
Firebase for getting unread posts
How to get all documents in a firestore subcollection based on the parent´s doc values?
【问题讨论】:
标签: firebase flutter google-cloud-firestore