我正在云函数中创建一个操作,以便在代码发生更改时返回值。但它正在犯一个错误。我做错什么了?
const functions = require('firebase-functions');
exports.alertHelp = functions.firestore
.document('chamados/{userId}')
.onWrite((change, context) => {
const snapshot = change.after;
const val = snapshot.val();
const name = val.tid;
console.log(name);
});TypeError: snapshot.val is not a function
at exports.alertHelp.functions.firestore.document.onWrite (/workspace/index.js:8:30)
at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:134:23)
at Promise.resolve.then (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:198:28)
at process._tickCallback (internal/process/next_tick.js:68:7) 发布于 2020-10-28 07:46:27
您正在编写Firestore触发器,这意味着您正在使用Firestore API来描述正在编写的文档。snapshot是一个DocumentSnapshot类型的对象。它有一个名为data()的方法来获取文档数据。没有val()方法。val()是您在实时数据库快照中找到的,它是一个完全不同的数据库和应用编程接口。
https://stackoverflow.com/questions/64564479
复制相似问题