Reputation:
I want to assign to a const
the name value inside parent
exports.myFunction = functions.database.ref('/messages/{pushId}/likes')
.onWrite(event => {
const name = event.parent.data.val().name; // this doesn't work. how do I properly get the name which is located in /messages/{pushId} ?
});
Upvotes: 1
Views: 2155
Reputation: 195
after version update
event <- (change, context)
event.data <-change.after
exports.myFunction = functions.database.ref('/messages/{pushId}/likes')
.onWrite((change, context) => {
return change.after.ref.parent.child('name').once('value').then(snapshot => {
const name = snapshot.val();
});
});
Upvotes: 0
Reputation: 7546
According to the documentation, this is how you access data from another path:
exports.myFunction = functions.database.ref('/messages/{pushId}/likes')
.onWrite(event => {
return event.data.ref.parent.child('name').once('value').then(snapshot => {
const name = snapshot.val();
});
});
Upvotes: 2