获取上次更新信息 / Firebase

Mic*_*hel 2 ios firebase swift firebase-realtime-database

在 上使用数据库时Firebase,是否可以在 iOS 应用程序中使用某些标准 API 检查文档上次更新的日期(和时间)?我的意思是没有实现我自己的系统来知道它上次被触摸的时间。

例如,如果有一个字段“lastUpdate”时间戳会很方便。

Fra*_*len 6

Firebase 实时数据库和 Cloud Firestore 都不会自动向数据添加时间戳字段以进行写入。

如果您想要这样的字段,则必须自己添加,无论是从客户端还是从 Cloud Functions。

有关后者的一个简单示例,它跟踪数据库中的节点上次修改时间,请参阅repo 中的此文件夹functions-samples。主要代码:

exports.touch = functions.database.ref('/chat/{message}').onWrite(
    (change, context) => admin.database().ref('/lastmodified').set(context.timestamp));
Run Code Online (Sandbox Code Playgroud)