I have rather big data-set, possibly millions of objects and I need to trigger the child_added event and get the last added child. However whenever I start the service it triggers the event once for each initial child in the data-set.
How Can I avoid this behavior?
edit:
The suggested solution does not solve the problem - it is just ignoring it in my opinion. In my specific case I store the unique reference to other object as a name and it's value is other important data. The Priority on the record is set to the specific number in my case time stamp. I use this to retrieve the record to build a timeline so I need the option to save a new object with custom timestamp - not only current. Listener .on() on event child_added fits the need perfectly except fetching all the children upon the start. This in my opinion renders this feature absolutely pointless on any large collection.
You could use limit(1). Then the listener will fire once at the beginning, and then again each time a new child is added.
fireRef.limit(1).on('child_added', function() { /*code*/ });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With