我的客户文档包含链接预订,按照Google建议创建:
clients: {
clientkey1: {
name: Some Name,
reservations: {
reskey1: true,
reskey2: true
}
}
}
和预订文件:
reservations: {
reskey1: {
clientKey: clientkey1,
doctorName: Doctor Name
},
reskey2: {
clientKey: clientkey1,
doctorName: Doctor Name
},
reskey3: {
clientKey: clientkey2,
doctorName: Doctor Name
},
reskey4: {
clientKey: clientkey3,
doctorName: Doctor Name
},
reskey5: {
clientKey: empty
}
}
现在在客户的应用程序中,我必须列出他的预订,并计算所有预订,以获取有关他占据哪个部分的信息以及有多少地方仍然可用的信息。我可以使用clientKey下载所有预订和过滤器,但如何避免与其他客户端下载整个数据'预订数据?
有没有办法只从预订中下载密钥?
答案 0 :(得分:0)
不,但是you could count with Cloud Functions for Firebase。
exports.countReservations = functions.database.ref('/reservations/{id}').onWrite(event => {
const collectionRef = event.data.ref.parent;
const countRef = collectionRef.parent.child('reservationCount');
return countRef.transaction(current => {
if (event.data.exists() && !event.data.previous.exists()) {
return (current || 0) + 1;
} else if (!event.data.exists() && event.data.previous.exists()) {
return (current || 0) - 1;
}
});
});