如何使用云功能更新此 firestore 文档字段?

How to update this firestore document field using cloud functions?

我是 Firebase、Firestore 和云函数的新手。如何根据名为“LastUpdatedAt”的字段更新名为“status”的此文件

exports.hello = functions.firestore.document("RealtimeData/{anyMachine}/Params/{anyParams}")

字段“LastUpdatedAt”在 {anyParams} 中:看起来像

LastUpdatedAt: 1606844285038

从时间戳转换后

LastUpdatedAt: 1/12/2020 23:8:5

我如何编写一个云函数来将这个“LastUpdatedAt”与当前时间进行比较,如果时差大于 15,则 'status' 应该设置为离线,否则它应该在线。

如果要更新文档中的单个字段,那么首先应该通过文档ID检索文档,然后在指定字段的同时执行更新功能。

有关详细信息,您可以参考 documentation and Whosebug answer,其中讨论了有关 Cloud Firestore 的节点 js SDK 的简要说明。