使用 Cloud Functions for Firebase 检查名称是否存在
Check if name exists using 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' 是否已经存在。我该如何实现?
像这样:-
exports.addIt = functions.database.ref('/messages/{pushId}')
.onWrite(event => {
if(typeof event.data.val().creationDate != 'undefined')
return event.data.adminRef.update({"creationDate":Date.now()})
else // do not update anything
})
如何使用 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' 是否已经存在。我该如何实现?
像这样:-
exports.addIt = functions.database.ref('/messages/{pushId}')
.onWrite(event => {
if(typeof event.data.val().creationDate != 'undefined')
return event.data.adminRef.update({"creationDate":Date.now()})
else // do not update anything
})