EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 446 forks source link

Listening for child events on database.Refenence is not working. Any way to listen for child events on filtered query? #1611

Open maciej-bielecki opened 4 years ago

maciej-bielecki commented 4 years ago

In realtime database, what I want to achieve is to query the data (filter / limit etc.) and attach child event listener to be informed about changes.

In the firebase documentation there is shown way to listen for child events by calling .on() on reference and passing required event, i.e. child_added: https://firebase.google.com/docs/database/web/lists-of-data#listen_for_child_events

But passing child_added or any other child related event name seems not to work. It acts as value so all collection is passed on handler.

var commentsRef = firebaseWebApi.database().ref(`/comments`);
commentsRef.child(`collecion_name`).on('child_added', function(data, prevChildKey) {
      console.log(`child_added ${data.key}` + JSON.stringify(data.val()));
});

Is there any other way to listen for child events but on query that uses some filters? I did not seen a way both in Native API, or the Web API.