本文介绍了firebase / firestore docs查询不起作用 - javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 由于firestore是新的,我在使用它时遇到了问题。 我必须得到所有用户的收集并遍历它。但它没有用。 db.collection(users)。get()。then(function(querySnapshot){ console。 log(querySnapshot.data()); }); 它说:以下代码: callFireBase(mobileToCheck){ db.collection(users)。where(mobile_no,'==',mobileToCheck).get()。then( function(querySnapshot){ if(querySnapshot.exists){ var userData = querySnapshot.data(); var userId = querySnapshot.id; console.log(mobileToCheck + 存在于DB中; } else { console.log(mobileToCheck +不存在于DB中); } }); } 始终打印 923052273575数据库中不存在 即使存在,请参阅下图以供参考。在 解决方案看起来想要在文档集合上调用 .data(),而不是一个文档。请查看此代码是否有效: db.collection(users)。get()。then(function(querySnapshot)) { querySnapshot.forEach(doc => { console.log(doc.data()); }); })。catch(err => { console.log('获取文件时出错',错误); }); As firestore is new, i am having problems using it. I have to get Collection of all users and traverse it. But it is not working. db.collection("users").get().then(function(querySnapshot){ console.log(querySnapshot.data());});It says:And following code:callFireBase(mobileToCheck){ db.collection("users").where("mobile_no", '==', mobileToCheck).get().then(function(querySnapshot){ if (querySnapshot.exists) { var userData = querySnapshot.data(); var userId = querySnapshot.id; console.log(mobileToCheck + "Exist In DB"); }else{ console.log(mobileToCheck + "Do Not Exist In DB"); } });}Is always printing Even if it exists, See following image for reference. In docs they have told this (i have used) way. 解决方案 It looks that tou want to call.data() on collection of documents, not one document. Please see if this code works:db.collection("users").get().then(function(querySnapshot){ querySnapshot.forEach(doc => { console.log(doc.data()); });}).catch(err => { console.log('Error getting documents', err);}); 这篇关于firebase / firestore docs查询不起作用 - javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-22 11:04