1
如何使用Cloud Functions for Firebase检查名称是否存在?使用Cloud Functions for Firebase检查名称是否存在
我有以下数据结构:
而这种伪代码:
exports.addIt = functions.database.ref('/messages/{pushId}')
.onWrite(event => {
if(creationDate does not exist)
event.data.adminRef.update({"creationDate":Date.now()})
else // do not update anything
})
我要检查,如果 'creationDate' 已经存在。我如何实现这一目标?
你也将要返回来自更新的承诺(),以确保更新前是完整的云功能不会清理功能。 –
绝对!了解承诺对于实施Firebase云端功能至关重要。 @Jonathan Doe,请查看[Jen Person's Firecasts](https://www.youtube.com/playlist?list=PLl-K7zZEsYLkPZHe41m4jfAxUi0JjLgSM)。他们有很大的帮助! –
@RohanStark请在回答中加入'return',因为在更新完成之前,有时候Cloud Functions会清理干净。 –