Best way to update list of data when a child node updates

20 views
Skip to first unread message

Kirtan Thakkar

unread,
Jun 30, 2016, 10:35:34 AM6/30/16
to Firebase Google Group
I have a list of records containing amount and outstanding balance in firebase. I need to update outstanding balances if a user updates the amount in any of the record from the list. As the amount is updated, the outstanding balance should be updated for all other records till the latest date from the date the original record updated by the user.

For example,

{
    "details": {
        "-randomKey1": {
            "timestamp": 1000,
            "amount": 100,
            "outstanding": 100
        },
        "-randomKey2": {
            "timestamp": 2000,
            "amount": -50,
            "outstanding": 50
        },
        "-randomKey3": {
            "timestamp": 3000,
            "amount": 20,
            "outstanding": 70
        }
    }
}

if amount in -randomKey2 is updated, outstanding should be updated in -randomKey2 and -randomKey3 and so on till end. -randomKey1 will not have any impact because its timestamp is less than of randomKey2 which was updated by user.

Is there any way possible to recursively update with child_changed by updating the immediate next in the list in firebase?

Can I do this in a better way? Like batch update or anything? 

For some code reference, here is the stackoverflow question: http://stackoverflow.com/q/38098521/1820644 

Thank you,
Kirtan
Reply all
Reply to author
Forward
0 new messages