UPDATE - SOLVED: Error in referencing. (Mentioned in Comment). Sorry to take your time.
Whenever a user is assigned to a new manager, I want to remove their reference in the managedby node under the earlier manager. The user node (*) structure looks like this:
And the managed by(#) (separate node ) looks like this:
On changing the managed by in the user node:
Desired output after cloud function is done with:
My firebase cloud function is this:
exports.updatemanagedby = functions.database.ref('/users/{uid}/managedby').onUpdate(event => {
if (event.data.previous.exists()) {
var earlierHandler = event.data.previous.val();
console.log("earlierHandler ", earlierHandler)
var sourceId = event.params.uid;
console.log("Current UID ", sourceId)
console.log('/managedby/' + earlierHandler + '/' + sourceId);
var adaRef = admin.database().ref('/managedby/' + earlierHandler.handler + '/' + sourceId)
adaRef.remove()
.then(()=> console.log("removed"))
.catch((error)=>console.log("error is ",error))
}
})
On running I receive this on the cloud function log. It even console logs "removed" :
But there is no change in the managedby Node as given in (#). F515DYXZbU.....G2 remains there. What am I doing wrong?