使用firebase函数检查数据是否存在

时间:2017-06-30 15:23:33

标签: javascript firebase firebase-realtime-database google-cloud-functions

如何使用Firebase云功能检查days节点是否存在?

index.js内的伪代码:

if(days.exists())
{
    //do something
}

see data structure here

1 个答案:

答案 0 :(得分:3)

// outside of function body
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

// inside function body
return admin.database().ref('days').once('value').then(snap => {
  if (snap.exists()) {
    // do something
  }
});