Gilles Debunne
Gilles Debunne

Reputation: 305

Firebase: is child_removed called when parent is removed?

I'm managing a list of items with the following database structure:

root
  - mylist
    - item1: val1
    - item2: val2
    - ...

I attach child_added and child_removed event listeners to mylist and I (correctly) get notified when items are added or removed.

My question is: should I expect child_removed events for each item in the list in case mylist (i.e. the parent node) is removed?

The documentation is unclear, and in practice I witness both behaviors for two very similar lists. Shall I be notified (and there's something I do wrong for one of my lists), or is the other list notifying by chance?

In case child_removed notifications are not guaranteed, an option would be to listen to child_removed events on the root node too, and check if the key matches 'mylist'.

But that implies adding .read access to the entire root tree for this user. And with a deeper hierarchy, how to know when any of the parents is removed?

Any other way to thoroughly watch the content of a list, including the deletion of the list itself?

Using firebase JS SDK version 3.4.1

Upvotes: 2

Views: 732

Answers (1)

Gilles Debunne
Gilles Debunne

Reputation: 305

Looking more into this, I found the answer. For future reference:

Yes, child_removed will be called for each item, when itself or any of its ancestor is removed. See reference documentation.

The reason I did not see it in my case is because I called off on one of my listeners without enough parameters, resulting in an unsubscription of all my listeners.

Upvotes: 2

Related Questions