Keanu Lorenzo
Keanu Lorenzo

Reputation: 79

How to implement a 'value added only' listener using FireBaseDatabase.net

I tried to follow the instructions on how to set a real-time streaming code that would handle the changes made to a child as described here.

using Firebase.Database;
using Firebase.Database.Query;
using System.Reactive.Linq;
...
var firebase = new FirebaseClient("https://dinosaur-facts.firebaseio.com/");
var observable = firebase
  .Child("dinosaurs")
  .AsObservable<Dinosaur>()
  .Subscribe(d => Console.WriteLine(d.Key));

But the code seems to trigger every changes made to the child and returns all of its children every trigger. This becomes problematic as I handle the changes synchronously. So, is there a way to make it as a 'value added only' listener that is efficient?

Upvotes: 0

Views: 593

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598765

If you add an observer on /dinosaurs then any time something happens under dinosaurs you get the whole JSON of /dinosaurs. There is no way to only get the changes, even though most native Firebase SDK actually only synchronize the things that have changed on the wire.

If you want to get more granular data, consider storing that more granular data. For example, if you want to only process the delta in your client, consider storing only the delta in a separate node in your database. And then when you listen to just that node, you'll only get the updates and can process those.

Upvotes: 1

Related Questions