答案 0 :(得分:1)
将数据重组为更平坦。为了支持多个团队中的玩家,您可以创建一个引用Players
和Teams
的节点。
{
Players: {
-Ksegwegwegwg: {
name: "alex"
},
-K43yhwhyehwh: {
name: "david"
}
},
Team: {
-Knwgjkwn4333: {
name: "superstars"
}
},
InTeam: {
-Kwegbwegwwegw: {
player: "alex",
team: "superstars"
},
-Kwegbwegwwegw: {
player: "david",
team: "superstars"
}
}
}
您可以在玩家加入团队的任何时候添加InTeam
。
然后你可以这样查询:
const queryObservable = db.list('/InTeam', {
query: {
orderByChild: 'team',
equalTo: 'superstars'
}
});
// Result = [{player: "alex", team: "superstars"}, {player: "david", team: "superstars"}];