【发布时间】:2020-12-02 04:06:42
【问题描述】:
我正在实施典型的追随者/追随者/朋友+饲料系统。对于我数据库中的每个用户,我有 3 个子集合:“followers”、“following”和“friends”。目前,我正在尝试按照以下三个业务规则实施提要:
- Feed 按日期排序。
- 用户 A 可以在用户 B 的好友列表中而用户 B 不在用户 A 的好友列表中。
- 您可以看到那些您关注的用户也关注您或/和将您安排在他们的朋友列表中的用户的帖子。
就我而言,我想做的是在云函数中执行多次读取,因为实现第三条规则似乎并不容易......但现在我想知道是否可以进行查询这种风格(类似):
currentUserFollowingRef = db.collection(...).doc(userId).collection("following")
otherUserFollowingRef = db.collection(...).doc(otherUserId).collection("following")
otherUserFriendsRef = db.collection(...).doc(otherUserId).collection("friends")
// Some kind of intersection using queries (Pseudo)
U1 = currentUserFollowingRef.where(firebase.firestore.FieldPath.documentId(), "in", otherUserFollowingRef)
.limit(10).get();
// Other intersection
U2 = currentUserFollowingRef.where(firebase.firestore.FieldPath.documentId(), "in", otherUserFriendsRef)
.limit(10).get();
// Union of two sets using pure js
UFinal = U1 union U2 (using js)
/* Last step is to retrieve the last post of each user ordered by date using collection group queries */
有人知道如何做类似的事情来实现这一点(检索文档 也在其他收藏中)?
有什么需要考虑的吗?
谢谢。
【问题讨论】:
标签: firebase google-cloud-firestore nosql