如何使用Firebase进行统计? [英] How to use Firebase for statistics?
问题描述
我正在一个系统上,用户可以预订地点,而地点可以在CMS中看到这些用户.但是现在我想为这些场所创建统计信息.
I am working on a system where users can subscribe to places and places can see these users in their CMS. But now I want to create statistics for the places.
其中一些统计数据是:
- 有多少位男性/女性订阅了该地点.
- 我所在位置的用户年龄段.
这些统计信息在Firebase中如何工作?我可以创建一个函数,并在添加或删除某些内容时侦听placeUsers
节点.但棘手的是,我需要每个地方的统计信息.
How would these statistics work in Firebase? I could create a function and listen to the placeUsers
node when something gets added or deleted. But the tricky part is that I need statistics per place.
我不能在客户端这样做,因为一个地方可能会吸引数百万用户.
I can't do it client-side because a place could potentially get millions of users.
在这里,我粘贴了当前数据库设置(只是其中的一小部分).
Down here I pasted (a small fragment of) my current database setup.
{
"users": {
"<user-push-key>": {
"name": "",
"birthdate": 2138349423489,
"gender": "male"
}
},
"placeUsers": {
"<place-push-key>": {
"<user-push-key-1>": true,
"<user-push-key-2>": true,
"<user-push-key-3>": true
}
},
"places": {
"<place-push-key>": {
"name": "",
"location": ""
}
}
}
推荐答案
与大多数传统的SQL数据库不同,Firebase的实时数据库不适用于临时聚合查询.当数据流入/通过系统时,您将必须预先了解要跟踪和更新的统计信息.
Unlike most traditional SQL databases, Firebase's Realtime Database is not well suited for ad-hoc aggregation queries. You will have to know up front what stats you want to track and update them as the data streams into/through your system.
当然可以在此客户端进行操作,但实际上并不理想.这是使用刚发布的 Firebase云功能的理想用例.它最接近对传入消息进行清理的用例:
Doing this client-side is certainly possible, but indeed not ideal. This is a perfect use-case for using the just-released Cloud Functions for Firebase. It falls closest to the use-case of sanitizing incoming messages:
这篇关于如何使用Firebase进行统计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!