利用Firebase Cloud功能读取价值

时间:2018-10-06 19:23:13

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

我正在尝试读取存储在Firebase实时数据库中的值。

结构是这样的

test
  |____ name : testname

现在我正在这样做以检索数据

const functions = require('firebase-functions'); 
const admin = require('firebase-admin'); 
admin.initializeApp(); //init firebase admin

    exports.nameTest = functions.database.ref('/test/name')
        .onWrite((snapshot) => {
          //getting the name value from reference
          const original = snapshot.val();

          //displaying in log the value
          console.log('Name: ', original);

          //returning the value of the promise
          return snapshot.before.val();
        });

但是我无法从引用中获得该代码的名称,它说

  

snapshot.val不是函数

如何使用功能从Firebase检索值?

onWrite仅在仅对该引用进行更改时才会触发?我可以获取在没有任何触发器的情况下进行更改之前的内部值吗?

0 个答案:

没有答案