0
votes

I'm using firebase functions to run the code for my flutter app. That sends a push notification to my app. I want to get the token. But I'm getting null value at snap.val(). Here how my code looks like:

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

1 Answers

0
votes

Your code is querying Realtime Database, but the screenshot here is showing Firestore. These are completely different database systems. Your database query is simply finding nothing, because there is no data at the location of your query.

You will have to write your code using the Firestore APIs for nodejs to read the document you have shown here.