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會清理乾淨。 –