firebaserestfirebase-realtime-databaseevent-stream

Firebase realtime database REST event stream: do not download the whole tree


I am using the Firebase Realtime database REST API to stream events from the server when data gets uploaded (See https://firebase.google.com/docs/reference/rest/database#section-streaming-cancel)

However, when I start the event stream, it always downloads the whole tree. I do not need that, I only want to receive live changes. Example:

GET https://[PROJECT_ID].firebaseio.com/database.json

// I want to get rid of this event
event: put
data: {"path": "/", "data": {...}}  // very large JSON tree

// I want to keep subsequent events, to entries changed in that tree:
event: put
data: {"path": "/entry42", "data": {...}}  // small JSON tree, ok

Is there any way to tell the database to skip the first event? I do not need this data (as a get the current state in a different, much more efficient way). I only want live changes to data.


Solution

  • Realtime Database doesn't have a sense of "only things that changed since the last time I queried". That's just not a query you can make. What you can do instead is use something like a timestamp to determine what's new, and query the database using that timestamp to find only nodes that are newer than the last timestamp that you used for the prior query.