Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how not to trigger event child_added for initial children

Tags:

firebase

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.

like image 532
webduvet Avatar asked Jul 22 '14 15:07

webduvet


1 Answers

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*/ });

like image 144
Timothy Smith Avatar answered Oct 22 '22 03:10

Timothy Smith