0

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.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
roiberg
  • 13,629
  • 12
  • 60
  • 91

1 Answers1

2

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:

Community
  • 1
  • 1
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807