Why is it that I can't seem to update a result set. I have 1000 items and I query Firebase and get back a DataSnapShot array. I want to check each element of the array and if a condition exists, then change the "type" to a "C". I get no errors, yet the update does not appear to have been applied. I'm doing this in the promise that is returned and yet the update is "ignored".
var db = admin.database();
var ref = db.ref("/calendars");
ref.once("value", function(snapshot) {
snapshot.forEach(function(data) {
var obj = data.val();
if (someconditionIsTrue) {
var objToUpdate = `calendars\\${data.key}`;
console.log(`Should update ${objToUpdate}`);
var entryRef = db.ref("/calendars").child(data.key).child('type');
entryRef.transaction(function(t) {
console.log(`TYPE: ${t}`); // DISPLAYS NULL EVEN THOUGH THERE IS A CHAR IN DB
return "C"; // Should change TYPE in the record to a "C"
});
}
Also tried just to do a set inside the forEach at well but that does not work either (which is why I thought i had to use a transaction).