Javascript TypeError:change.after.val不是函数firebase
您好,我正在尝试读取firestore数据库中的更改Javascript TypeError:change.after.val不是函数firebase,javascript,node.js,firebase,google-cloud-firestore,google-cloud-functions,Javascript,Node.js,Firebase,Google Cloud Firestore,Google Cloud Functions,您好,我正在尝试读取firestore数据库中的更改 'use stricts' const functions = require('firebase-functions'); const admin = require('firebase-admin'); const nodemailer = require('nodemailer'); require('dotenv').config(); admin.initializeApp(functions.config().firebase
'use stricts'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const nodemailer = require('nodemailer');
require('dotenv').config();
admin.initializeApp(functions.config().firebase);
exports.sendOrderCompletionEmail = functions.firestore.document('/service-requests/{req_id}')
.onUpdate((change, context) => {
const req = context.params.req_id;
const sts = change.after.val(); //Error on this line
console.log(sts);
});
我得到了这个错误
TypeError: change.after.val is not a function
我想读取我的文档中的更改并返回更改的字段值,因为您正在通过更新Firestore文档触发您的云功能,所以您需要执行以下操作
const sts = change.after.data();
有关更多详细信息,请参阅
事实上,我们对事件触发的云函数使用val方法
Firebase提供两种NoSQL数据库解决方案:云Firestore和实时数据库。有关更多详细信息,请参阅此部分。由于您通过更新Firestore文档触发了云功能,因此需要执行以下操作
const sts = change.after.data();
有关更多详细信息,请参阅
事实上,我们对事件触发的云函数使用val方法
Firebase提供两种NoSQL数据库解决方案:云Firestore和实时数据库。有关更多详细信息,请参见此