本文介绍了Cloud Functions-Cloud Firestore错误:无法获取serverTimestamp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

Cloud Functions-Cloud Firestore错误:无法获取serverTimestamp

Cloud Functions - Cloud Firestore error: can't get serverTimestamp

const admin = require('firebase-admin');
    exports.userlog = functions.firestore
    .document('user/{userId}')
    .onUpdate((change, context) =>
    {
        const db = admin.firestore();
        //var timestamp = db.FieldValue.serverTimestamp();
        var timestamp = db.ServerValue.TIMESTAMP;
        ...
        return db.collection('userlog').add(
        {
            userId : previousValue.userId,
            ...
            timestamp: timestamp
        }).then(ref =>
        {
            return console.log('Added document with ID: ', ref.id);
        });
    });

我分别遇到两个错误:

TypeError:无法读取未定义的属性"TIMESTAMP"

TypeError: Cannot read property 'TIMESTAMP' of undefined

推荐答案

正确的语法是:

firebase.firestore.FieldValue.serverTimestamp()

请注意,在firestore之后没有括号(()):这是一个静态变量,而不是实例变量/成员字段.

Note the lack of parenthesis (()) after firestore: this is a static variable, not an instance variable/member field.

这篇关于Cloud Functions-Cloud Firestore错误:无法获取serverTimestamp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 16:27