Reputation: 83
I have function and I want this function remove child when child added to "History"child. I am getting error below,when I add child to "History"child.
Here is my function code :
exports.onHistoryAdded = functions.database.ref('/Users/Customers/{pushId}/History/{pushID}')
.onWrite((snapshot, context) => {
var pushId=snapshot.key;
return snapshot.ref.parent.child(pushId).remove();
});
Upvotes: 1
Views: 1230
Reputation: 600100
Your code doesn't seem to have been correctly updated from the beta version of Firebase Functions to the 1.0 release.
In the latest release, the first argument to onWrite
is a change
and not a snapshot
. You can get the latest snapshot from change.after
. So:
exports.onHistoryAdded = functions.database.ref('/Users/Customers/{pushId}/History/{pushID}')
.onWrite((change, context) => {
var snapshot = change.after;
var pushId=snapshot.key;
return snapshot.ref.parent.child(pushId).remove();
});
Upvotes: 4