简体   繁体   English

TypeError: 'Reference' object 在 java 脚本中不可迭代

[英]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.

相关问题 如何解决 'datetime.datetime' object is not iterable' TypeError - how to solve 'datetime.datetime' object is not iterable' TypeError 未捕获(承诺)TypeError:undefined is not iterable - Uncaught (in promise) TypeError: undefined is not iterable java.lang.NullPointerException:尝试在 null object 引用上调用虚拟方法“boolean java.lang.String.equals(java.lang.Object)” - java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference TypeError: Object(...) 不是 function(匿名函数) - TypeError: Object(...) is not a function (anonymous function) 所需参考处不存在 object - No object exists at the desired reference Android studio null object 参考错误 - Android studio null object reference error × TypeError:无法解构'Object(...)(...)'的属性'currentUser',因为它是未定义的 - × TypeError: Cannot destructure property 'currentUser' of 'Object(...)(...)' as it is undefined Expo 项目类型错误:未定义不是 object(评估“_firebase.default.firestore”) - Expo project TypeError: undefined is not an object (evaluating '_firebase.default.firestore') 尝试在 android studio firebase mainactivity 中的空对象引用上调用虚方法 boolean java.lang.String.equals(java.lang.Object) - Attempt to invoke virtual method boolean java.lang.String.equals(java.lang.Object) on a null object reference in android studio firebase mainactivity 尝试在空对象引用上调用虚拟方法“…………” - Attempt to invoke virtual method '.........' on a null object reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM