Wednesday 26 April 2017

How to update one Firebase child of existing parent without new key?

I have a data structure like this in Firebase web:

Users:  
**-KixIFileAu48UrbAI8k**  
--name: Chris  
--state: 0  
--contact: www.site.com/emailLink   
**-KvxTFdleAu4rUrbAI8z**  
**-KetdTdWefu4rtrbER0q**

I created a Node JS bot that checks whether the state is equal to 0 for each user, and if so, goes to the contact link and grabs their email listed there. From there, I want my bot to change the state from 0 to 1 so that I & the bot know it has been reviewed already.

I can't for the life of me figure out how to update this. It seems like the firebase tutorial asks me to push a new key, which I don't understand.

Why can't I do something like this:

firebase.database().ref('Users').child('state').update("1");

If I try that, I get this:

Error: Firebase.update failed: First argument  must be an object containing the children to replace.

This seems like something super straight forward and yet I can't figure it out.

After that, could I use the same method to push a new (previously non-existent) Email child to each user with the Email address I got?



via ryangineer

No comments:

Post a Comment