Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
311 views
in Technique[技术] by (71.8m points)

node.js - Get Data from Firebase Firestore in Cloud Function

I am trying to get data from firestore in functions of firebase Node JS 8.

I receive a QueryDocumentSnapshot which is totally fine but i cannot get data from this.

I want androidNotificationToken but i get error undefined.

I am tring this

    const missing_owner = snapshot.data().missing_owner;
const found_owner = snapshot.data().found_owner;

console.log("Missing Owner",missing_owner); //this is working


const missRef = admin.firestore().collection(`users`).doc(`${missing_owner}`);
const foundRef = admin.firestore().collection(`users`).doc(`${found_owner}`);

const doc1 = await missRef.get();
const doc2 = await foundRef.get();

console.log("Data is ",doc1); //this is also working


const androidNotificationTokenMisser = doc1.data().androidNotificationToken; //cant get this 
const androidNotificationTokenFounder = doc2.data().androidNotificationToken; // and this

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There was some problem with fetching the string with name androidNotificationToken from the firestore, so I renamed it to token and now it is working.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...