从云功能中的父级获取数据?

Get data from parent in Cloud Function?

我想将父项

中的名称值分配给const
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} ?
    });

根据 the documentation,这是从另一个路径访问数据的方式:

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();
    });
});

版本更新后

事件<-(变化,背景)

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();
});

});