webduvet
webduvet

Reputation: 4292

how not to trigger event child_added for initial children

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.

Upvotes: 9

Views: 3478

Answers (1)

Timothy Smith
Timothy Smith

Reputation: 848

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

Upvotes: 3

Related Questions