node.js:firebase快照返回null

时间:2020-06-22 16:38:38

标签: javascript node.js firebase firebase-realtime-database google-cloud-functions

我正在使用firebase函数为我的flutter应用程序运行代码。这会将推送通知发送到我的应用程序。我想获得令牌。但是我在snap.val()处得到了空值。我的代码如下:

const functions = require('firebase-functions');
var admin = require("firebase-admin");

admin.initializeApp();

var db = admin.database();

exports.CreateTicket = functions.firestore
    .document('tickets/{username}')
    .onCreate((snapshot, context) => {

        console.log(snapshot.data().clientUid);// this one working fine.

        var ref = db.ref("token/BX3jXKVpOkRa80SIKb7jPwfbU0c2/");
        ref.once("value", (snap) => {
            console.log(snap.val()); // this one getting null,

        });
    });

enter image description here

1 个答案:

答案 0 :(得分:0)

您的代码正在查询实时数据库,但此处的屏幕截图显示了Firestore。这些是完全不同的数据库系统。您的数据库查询只是找不到任何东西,因为查询位置没有数据。

您必须使用Firestore APIs for nodejs编写代码才能阅读此处显示的文档。