javascript - Firebase Cloud Functions onUpdate 触发器向 Firestore 返回不可靠的时间戳
问题描述
我在 Cloud Functions 中有一个简单的函数,当我的 Cloud Firestore 数据库中的“客户端”位置发生任何更新时会触发该函数。
问题是,当我更新数据时,一旦将文档的 lastUpdated 子项更改为秒 1572841408099,然后我再次更改子项,它总是将 lastUpdated 恢复为当时的 Cloud Firestore 时间戳:“2019 年 11 月 3 日UTC-6 晚上 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});
}
});
为什么它会在第二次暗示后恢复到过去一段时间的常规时间戳?此外,为什么每次更新时它会在秒数和时间戳之间跳转?
解决方案
推荐阅读
- asp.net - 如何在 SQL Server 中创建在特定时间仅执行一次的触发器
- python - 如何在python3中的'\ + 234'字符串中提取'\ +'
- javascript - JavaScript:我们如何将数组推入数组中?
- php - 找不到用于在 joomla db 中插入文章的良好编码
- reactjs - Jest check if an elements attribute exists
- php - 在本地运行 Codeclimate
- django - 如何将python列表导出到excel表中
- javascript - 正则表达式:如何从(RegexA)之类的东西中排除空匹配?(RegexB)?(RegexA)?
- assembly - 如何将汇编语言循环部分更改为二进制代码?
- tornadofx - 在 Tabpane TornadoFX 中的选项卡内切换选项卡