[英]TypeError: 'Reference' object is not iterable in java script
i want to retrieve data from firebase to javascrip.我想从 firebase 检索数据到 javascrip。 how i get some data and get output data to the variable.我如何获取一些数据并将 output 数据获取到变量。 this is my code这是我的代码
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.sendNotificationUser = functions.firestore
.document('donorRequests/{donorRequestId}')
.onWrite((snapshot, context) => {
var tokens = [];
// var accounts = admin.firestore().collection('accounts').where("bloodType", '==', record.bloodType).where("rhesus", '==', record.rhesus).get();
for (const i of accounts) {
tokens.push(account.val().token);
}
var payload = {
"notification":{
'title': 'Hai Pahlawan!',
'body': 'Seseorang butuh kamu, yuk kita bantu :)'
}
}
admin.messaging().sendToDevice(tokens, payload);
})
and the error message is错误信息是
TypeError: accounts is not iterable类型错误:帐户不可迭代
anyone can help me任何人都可以帮助我
As you can see from the API documentation , Firestore's query.get()
returns a promise that resolves with a QuerySnapshot object. You're going to have to use that promise to wait for the query to complete, then iterate the documents in the QuerySnapshot object.正如您从API 文档中看到的那样,Firestore 的query.get()
返回一个 promise,它使用QuerySnapshot object 解析。您将不得不使用该 promise 等待查询完成,然后迭代 QuerySnapshot 中的文档object。
I suggest starting with the documentation to learn how queries work with Firestore, and see some examples.我建议从 文档开始,了解查询如何使用 Firestore,并查看一些示例。
Also, you're going to have to learn how JavaScript promises work with Cloud Functions.此外,您还必须了解 JavaScript 承诺如何与 Cloud Functions 配合使用。 You must deal with the promise from the query and the promise from sendToDevice
correctly, or the function won't work.您必须正确处理查询中的 promise 和 sendToDevice 中的sendToDevice
,否则 function 将无法工作。 See the documentation for details.有关详细信息,请参阅 文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.