Cloud Features for Firebase - Multiplayer Update

Using cloud functionality for Firebase is the best way to trigger an update of multiple locations in a hierarchy? My main goal is to update the value for all users in the list. I have created the following example that works, but I want to confirm that this is the correct way.

Database Hierarchy: Database Structure

This function starts based on update and then updates the list of other nodes:

exports.multiLocationUpdateTest = functions.database.ref('/atest/update').onWrite(event => {
        console.log('here');
        var mergedUpdate = {};
        mergedUpdate[ 'list/item1/val1' ] = true;
        mergedUpdate[ 'list/item2/val2'  ] = true;
        mergedUpdate[ 'list/item3/val3'  ] = true;

        return event.data.ref.parent.update(mergedUpdate);
 });

      

It will update each of val1, val2, val3 to true as expected.

Is this the correct approach and is it guaranteed to be transactional? those. is it possible that only val1 gets updated and the rest fail?

+3


source to share





All Articles