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?
function getUser(Users){
var keys = Object.keys(Users);
var User = Users[keys[i]];
var id = keys[i];
var state = User.state;
var contact = User.contact;
if(contact != "" && contact != undefined){
console.log("Key:"+id);
firebase.database().ref("Users").child(keys[i]).child("state").set("1");
This ended up fixing the problem. The last line of this code is what I used and it worked great!