【问题标题】:TypeError: change.after.val is not a function firebaseTypeError:change.after.val 不是一个函数 firebase
【发布时间】:2020-10-02 12:03:35
【问题描述】:

您好,我正在尝试读取我的 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);

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

我想读取文档中的更改并返回更改的字段值

【问题讨论】:

    标签: javascript node.js firebase google-cloud-firestore google-cloud-functions


    【解决方案1】:

    由于您是通过更新 Firestore 文档来触发 Cloud Function,因此您需要这样做

    const sts = change.after.data();
    

    有关详细信息,请参阅doc


    事实上,我们将val() 方法用于由Realtime Database 事件触发的云函数。

    Firebase 提供两种 NoSQL 数据库解决方案:Cloud Firestore 和实时数据库。有关详细信息,请参阅此doc

    【讨论】:

      猜你喜欢
      • 2019-03-12
      • 2018-11-27
      • 2021-01-25
      • 2018-03-24
      • 2021-11-18
      • 2019-11-05
      • 2020-07-22
      • 2022-01-19
      • 1970-01-01
      相关资源
      最近更新 更多