When removing an item from my RTDB, my intention is to clean up user's likes if the item they like got removed.
With my data structure like so:
I am attempting to remove the nodes like this:
const updates = {};
//WORKS
updates[`/strains/${title}/`] = null;
updates[`/strainsMin/${title}/`] = null;
firebase
.database()
.ref('reviews')
.orderByChild('s')
.equalTo(title)
.once('value', snapshot => {
console.log(snapshot.val())
snapshot.forEach(child => {
console.log(child.key)
//WORKS
updates[`/reviews/${child.key}`] = null;
});
})
.then(() => {
firebase
.database()
.ref('userLikedStrains')
.orderByChild(title)
.equalTo(title)
.once('value', snapshot => {
console.log(snapshot.val() + 'likeylikeyyy')
snapshot.forEach(child => {
console.log(child.key)
//DOESNT WORK
updates[`/userLikedStrains/${child.key}/${title}`] = null;
});
firebase
.database()
.ref()
.update(updates);
})
For some reason this doesn't work. Is it because I am targeting a key (which is still a child?..)
I appreciate any help with this! Cheers.