Node.js firebase云函数中更新的firestore文档的更改数据返回undefined

Node.js firebase云函数中更新的firestore文档的更改数据返回undefined,node.js,firebase,google-cloud-firestore,google-cloud-functions,Node.js,Firebase,Google Cloud Firestore,Google Cloud Functions,我正在使用firestore onUpdate触发器并尝试获取 更新的文档(字段名、新值) 我希望在用户的个人资料中添加新标记后通知用户,例如: 新的分数是50 但当我在通知正文中显示它们时,它会显示: 以下是完整的云函数片段: const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(); //functions.config()

我正在使用firestore onUpdate触发器并尝试获取 更新的文档(字段名、新值)

我希望在用户的个人资料中添加新标记后通知用户,例如:

新的分数是50

但当我在通知正文中显示它们时,它会显示:

以下是完整的云函数片段:

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp();
//functions.config().firebase
exports.updateUser = functions.firestore
    .document('stuThird/{userId}/stuMarks/{markId}')
    .onUpdate((change, context) => {
      // Get an object representing the document
      // e.g. {'name': 'Marie', 'age': 66}
      const newValue = change.after.data();

      // ...or the previous value before this update
      const previousValue = change.before.data();

      // access a particular field as you would any JS property
      const name = newValue.name;
      var body = ' the new mark of' + name + 'is'+ newValue;
      if(newValue){

      var message = {
        notification: {
            title: 'new mark changed',
            body:   body,
        },
        topic: 'bebo'
    };
  }

    // Send the message.
    return admin.messaging().send(message)
        .then((message) => {
           return console.log('Successfully sent message:', message);
        })
        .catch((error) => {
            console.error('Error sending message:', error);
        });
      // perform desired operations ...
    });
**

以下是数据库:

**

添加您的数据库此处信息不足。我们需要能够看到正在更新的文档的确切内容,以及触发此功能的您对文档所做的更改。另外,你的问题应该解释你期望在这个函数中发生什么,这与你所观察到的不同。在这两种情况下,你似乎都得到了整个对象,而不是你想要的部分。请按照Doug的建议为我们提供更多信息。Doug请查看我的编辑。请注意,我正在更新stuMarks集合中任何文档的三个整数值之一,以触发通知
const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp();
//functions.config().firebase
exports.updateUser = functions.firestore
    .document('stuThird/{userId}/stuMarks/{markId}')
    .onUpdate((change, context) => {
      // Get an object representing the document
      // e.g. {'name': 'Marie', 'age': 66}
      const newValue = change.after.data();

      // ...or the previous value before this update
      const previousValue = change.before.data();

      // access a particular field as you would any JS property
      const name = newValue.name;
      var body = ' the new mark of' + name + 'is'+ newValue;
      if(newValue){

      var message = {
        notification: {
            title: 'new mark changed',
            body:   body,
        },
        topic: 'bebo'
    };
  }

    // Send the message.
    return admin.messaging().send(message)
        .then((message) => {
           return console.log('Successfully sent message:', message);
        })
        .catch((error) => {
            console.error('Error sending message:', error);
        });
      // perform desired operations ...
    });