Jump to content

How do I programatically detect when a new tree is added in firebase real time database?

If I add a new tree in Firebase, how do I detect that a new tree has been added in Java and Swift? I only want to detect when an item directly below the root has been added, not if any sub-fields have been added/updated.

Link to comment
Share on other sites

Link to post
Share on other sites

Who is doing the adding? It's probably more efficient if an event/push message is sent by whoever/whatever is adding the new entry, rather than detecting these changes some other way.

 

~edit: To expand on this a bit: The primary purpose of a database is to store and retrieve data as quickly and efficiently as possible. It is not meant as a communications channel. You shouldn't expect your database to notify you about changes. Likewise, constantly scanning your database for changes isn't very efficient.

 

If multiple programs share the database and you need to know when something is added (e.g. to refresh what is shown on screen) then you should use a separate mechanism for that. Like i said above, have your programs notify one another with events, push messages or the like.

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

On 4/12/2020 at 11:55 PM, DashKat said:

If I add a new tree in Firebase, how do I detect that a new tree has been added in Java and Swift? I only want to detect when an item directly below the root has been added, not if any sub-fields have been added/updated.

FIrst of all, why not use Firestore? The realtime db is about to be deprecated.

 

Anyway, have a look here. You can't just watch for changes in a specific tree level with the realtime database. What you can do is listen to ALL changes and ignore the changes in the subtrees.

FX6300 @ 4.2GHz | Gigabyte GA-78LMT-USB3 R2 | Hyper 212x | 3x 8GB + 1x 4GB @ 1600MHz | Gigabyte 2060 Super | Corsair CX650M | LG 43UK6520PSA
ASUS X550LN | i5 4210u | 12GB
Lenovo N23 Yoga

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×