I need to update the values of a specific userID linked to multiple post keys in my database by setting the userID to null. The userIDs are associated with post keys located in the path: posts/ivies/userIDs in my database. Take a look at how the database is structured:
https://i.sstatic.net/FE4ZC.png
To accomplish this, I created a loop to search for the userID and change it to null like so:
exports.wipeData = functions.https.onRequest(async (req, res) => {
const original = 'ppPXA8MvaSRVbmksof0ByOzTxJ92';
const snapshot = await admin.database().ref('/posts/ivies/userIDs/');
console.log((snapshot));
for (let value in snapshot.val) {
if (value == original) {
snapshot.val.set("null")
}
else {
console.log(value)
}
}
res.redirect(303, snapshot.ref.toString());
// [END adminSdkPush]
});
Even though this code executes without errors, it fails to replace 'ppPXA8MvaSRVbmksof0ByOzTxJ92' with 'null' as expected. Any assistance would be greatly appreciated. Thanks!