Firebase DataChanged Help

Is there any way to narrow the detection of what keys were changed in the database? Currently, even if I add a listener block that is narrowed down to a tag within a bucket, if the same tag name is found in other buckets, the datachanged block will detect it as well. How can I work around this?

I think this can be avoided by specifying the full path to the keys. What blocks do you use to detect changes? I would like to see a piece of data structure.

1 Like


thunkable2
I am using the blocks to try and listen to when the tag in testing (not testing2) is changed, but the app seems to ignore my pathing and use the last reference point to listen for so the code below {if key = tag} gets executed but the one with the pathing doesn’t. Although I think I’m doing it wrong… I ran into another problem which is that as soon as the listener block is executed, the datachanged block seems to also execute instantly even though I haven’t attempted to change any data within the database yet. Please educate me on how the whole DataChanged and Listener blocks work.

The problem is that “key” only returns the last segment of path, not the full path, as it should be. Therefore, if you put two listeners on testing/tag and testing2/tag, “key” in both cases will return the tag, not testing/tag or testing2/tag. Simply put, the current implementation of the DataChanged block does not allow to determine the node in which the change occurred. It allows you to determine only that some change in the database has occurred.

How is the node in which the change occurred? To do this, you must add a path to it when saving the value. For example, you save “Hello”, and Hello#testing2/tag should be written to the database. And when getting the value, you need to divide the line by # and return Hello as the value, and the path is testing2 / tag. But this method will only work if the recording goes through the application in which this mechanism is configured.