简体   繁体   English

从云中的 Firebase Firestore 获取数据 Function

[英]Get Data from Firebase Firestore in Cloud Function

I am trying to get data from firestore in functions of firebase Node JS 8.我正在尝试从 firebase Node JS 8 的函数中的 firestore 获取数据。

I receive a QueryDocumentSnapshot which is totally fine but i cannot get data from this.我收到一个 QueryDocumentSnapshot 完全没问题,但我无法从中获取数据。

I want androidNotificationToken but i get error undefined.我想要 androidNotificationToken 但我得到未定义的错误。

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

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.从 Firestore 中获取名为 androidNotificationToken 的字符串时出现了一些问题,因此我将其重命名为 token,现在它可以正常工作了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 firebase 云 function 从云 Firestore 读取数据? - Read data from cloud firestore with firebase cloud function? 使用 Firebase 云从 Cloud Firestore 读取数据 function - Read data from Cloud firestore with Firebase cloud function 使用 Google Cloud Function 将数据从 firebase firestore 导出到 MeiliSearch - Exporting data from firebase firestore to MeiliSearch using Google Cloud Function 本地云功能Firebase将数据添加到Firestore - Local Cloud Function Firebase add data to Firestore 从 firestore 文档中获取数据并在云端使用 function - Get data from firestore document and use in cloud function Firebase Cloud Function:Cloud Firestore 查询无效,即使数据在 Cloud Firestore 中 - Firebase Cloud Function : Cloud Firestore query invalid eventhough data is in Cloud Firestore Firebase:Firestore 未更新 Cloud Function 的计划函数中的数据 - Firebase : Firestore not updating data in Cloud Function's scheduled function 使用云函数 onCreate 从 firebase firestore 中 onCreate 的集合/文档中检索数据 - Retrieve data from collection/document inside of onCreate in firebase firestore with cloud function onCreate 数据未通过调度程序 function 和 Firebase Cloud Functions 保存到 Firestore - Data not saved into Firestore through scheduler function with Firebase Cloud Functions 运行 Cloud Function 将 Firebase 经过身份验证的用户数据存储到 Firestore - Run Cloud Function to store Firebase Auth'ed user data to Firestore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM