mardi 4 août 2020

Firebase Realtime Database - Web / Javascript - how to to execute multiple write operations as a single batch

I noticed the Firebase Firestore give us the option to execute multiple write operations as a single batch that contains any combination of set(), update(), or delete().

Is it possible on Firebase Realtime as well?


Basically, I have the following data:

main: {
    first: {
        keywords: {
            one: { active: false, required: false },
            two: { active: false, required: false },
            three: { active: false, required: false },
        }
    }
}

I have created an action to update a single value like this:

database.ref(`main/${category}/keywords/${keyword}/`).update({ active })
     

I need to create a new action to update the active value of all keywords' children at once.

I know that I could update the "keywords" just by updating the whole object like this:

database.ref(main/${category}/keywords).update(UPDATED OBJECT HERE)

However, just out of curiosity is there a way where I could just loop into keywords and update specific values? Maybe something like this?

database.ref(`main/${category}/keywords/`).forEach(item => item.update({ active }))



Aucun commentaire:

Enregistrer un commentaire