Firebase Cloud Functions onUpdate触发器将不可靠的时间戳返回给Firestore

我在Cloud Functions中有一个简单的函数,当Cloud Firestore数据库中“客户端”位置发生任何更新时,就会触发该函数。

问题是,当我将数据更改为文档的lastUpdated子项(已更新为秒)时更新数据1572841408099,然后再次更改该子项时,它总是将lastUpdated还原为该时间的Cloud Firestore时间戳:“ 11月“ UTC-6,2019年3月3日晚上9:44:16”,无论实际上是几点。

如何获取以下代码以可靠地返回数据何时更新?

import * as functions from 'firebase-functions';

export const clientUpdatedTask = functions.firestore.document('clients/{clientId}').onUpdate((change: any,context: any) => {
    const before = change.before.data();
    const after = change.after.data();
    const timeEdited = Date.now();
    if(before.lastUpdated.seconds !== after.lastUpdated.seconds) {
        return 'The Time Did Not Change. No Need To Run Update!';
    } else {
        return change.after.ref.update({'lastUpdated' : timeEdited},{merge: true});
    }
});

为什么它会在第二次暗示后又恢复为过去一段时间的常规时间戳记?此外,为什么每次更新都在秒和时间戳之间跳转?

tpl1123 回答:Firebase Cloud Functions onUpdate触发器将不可靠的时间戳返回给Firestore

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3169105.html

大家都在问