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

て烟熏妆下的殇ゞ 提交于 2020-01-13 10:35:10

问题


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);
        });
    });

I got two errors separately:

TypeError: Cannot read property 'serverTimestamp' of undefined

TypeError: Cannot read property 'TIMESTAMP' of undefined


回答1:


The correct syntax is:

firebase.firestore.FieldValue.serverTimestamp()

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



来源:https://stackoverflow.com/questions/50361962/cloud-functions-cloud-firestore-error-cant-get-servertimestamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!