做一些关于firebase数据库的数据 [英] Do some work on the data on firebase database

查看:109
本文介绍了做一些关于firebase数据库的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Firebase中的数据,我有没有办法做一些工作?
ie:我想从客户端发送一个数字,并让数据库计算出它的平均值,并存储结果的新数字。



现在似乎客户需要做计算,但由于同时发生的请求,它不好,不准确。

没有服务器端的聚合原语。

这个限制最常用的解决方法是:

$ ol每次需要时,$ b

  • 计算客户端上的移动聚合。例如,每当你添加一个新的数字,你可以用一个事务来更新平均值,如 average =(99 * average + newValue)/ 100


  • 有一台服务器进行聚合。优选地,对于流操作,由于批量操作趋于妨碍数据库的实时操作。


  • 一些相关的问题:


    I there any way of doing some work on the data in Firebase? i.e: I want to send a number from the clients and have the DB calculate an average of it and and store the result new number.

    Right now it seems like the clients need to do the calculation but it's not good and not accurate because of the simultaneous requests.

    解决方案

    The Firebase Database has no server-side aggregation primitives.

    The most common workarounds for this limitations are to:

    1. calculate a moving aggregate on the client every time it is needed. For example, whenever you add a new number you can update the average with a transaction as average = (99*average + newValue)/100

    2. have a server do the aggregation. Preferably also with a streaming operation, as bulk operations tend to get in the way of the realtime operation of the database.

    A few related questions:

    这篇关于做一些关于firebase数据库的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆