【问题标题】:node.js: firebase snapshot return nullnode.js:firebase 快照返回 null
【发布时间】:2020-10-12 14:26:52
【问题描述】:

我正在使用 firebase 函数来运行我的颤振应用程序的代码。这会向我的应用程序发送推送通知。我想得到令牌。但我在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,

        });
    });

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-12-05
      • 1970-01-01
      • 1970-01-01
      • 2020-11-07
      • 2020-08-05
      • 2017-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多