Firebase 查询到节点
Firebase query into nodes
一个问题,我该如何查询?
架构
-|conversations
-|$uid
-|fromID
-|message
name: string
date: date
body: string
like: boolea
如果用户是消息的发送者,那么关注者都是collections进入conversations/$uid
,被关注的用户在conversations/ANYTHING/$uid
.
我可以这样列出关注者this.followers = this.af.database.list(conversations/${this.currentAuth.uid});
但是,还有关注的用户呢?
添加此图以更好地解释
因此,使用 database.list,您会收到一组消息。
对于列表中的每条消息,您都有添加的元数据。
您可以使用以下密钥获取您的消息的密钥(因此跟随的用户 ID):"$key"
示例:
const message = this.af.database.list(conversations/${this.currentAuth.uid});
message[0].$key
将为您提供关注用户的 user_id。
编辑 1:
我不太明白你想做什么。但是你在评论中的建议是:
这将为您提供所有与 this.currentAuth.uid 作为 fromID:
的对话
_.filter(
this.af.database.list(conversations),
function (o) => {
return Object.keys(o).indexOf(this.currentAuth.uid) != -1
}
)
解决方案是添加两个节点。关注者并关注每个个人资料以保存所有密钥。
一个问题,我该如何查询?
架构
-|conversations
-|$uid
-|fromID
-|message
name: string
date: date
body: string
like: boolea
如果用户是消息的发送者,那么关注者都是collections进入conversations/$uid
,被关注的用户在conversations/ANYTHING/$uid
.
我可以这样列出关注者this.followers = this.af.database.list(conversations/${this.currentAuth.uid});
但是,还有关注的用户呢?
添加此图以更好地解释
因此,使用 database.list,您会收到一组消息。
对于列表中的每条消息,您都有添加的元数据。
您可以使用以下密钥获取您的消息的密钥(因此跟随的用户 ID):"$key"
示例:
const message = this.af.database.list(conversations/${this.currentAuth.uid});
message[0].$key
将为您提供关注用户的 user_id。
编辑 1:
我不太明白你想做什么。但是你在评论中的建议是:
这将为您提供所有与 this.currentAuth.uid 作为 fromID:
的对话_.filter(
this.af.database.list(conversations),
function (o) => {
return Object.keys(o).indexOf(this.currentAuth.uid) != -1
}
)
解决方案是添加两个节点。关注者并关注每个个人资料以保存所有密钥。