Javascript 如何使用where in cloud firestore
我正在firebase函数中使用cloud firestore。我面临在查询中使用“where”的问题,因为我不知道确切的语法。如果我错了,请纠正我Javascript 如何使用where in cloud firestore,javascript,firebase,google-cloud-firestore,Javascript,Firebase,Google Cloud Firestore,我正在firebase函数中使用cloud firestore。我面临在查询中使用“where”的问题,因为我不知道确切的语法。如果我错了,请纠正我 self.dbManager.collection('test').where('entry_date', '==','2018-06-29').where('entry_status','==','active').get().then( async doc => { console.log("doc----
self.dbManager.collection('test').where('entry_date', '==','2018-06-29').where('entry_status','==','active').get().then( async doc => {
console.log("doc--------->",doc);
console.log("doc--------->",doc.data());
conv.data.userQuesData = doc.data()
});
当我使用“doc.data()”时,我得到了下面的错误。我们有上述条件的数据
TypeError: doc.data is not a function
at MYservice.<anonymous> (/user_code/services/myService.js:99:62)
at step (/user_code/services/myService.js:32:23)
at Object.next (/user_code/services/myService.js:13:53)
at /user_code/services/myService.js:7:71
at __awaiter (/user_code/services/myService.js:3:12)
at /user_code/services/daoService.js:94:168
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
TypeError:doc.data不是函数
为我服务。(/user_code/services/myService.js:99:62)
在步骤(/user\u code/services/myService.js:32:23)
在Object.next(/user\u code/services/myService.js:13:53)
at/user\u code/services/myService.js:7:71
在等待者处(/user\u code/services/myService.js:3:12)
at/user_code/services/daoService.js:94:168
在进程中。_tickDomainCallback(internal/process/next_tick.js:135:7)
执行查询时,返回包含对象的承诺
在代码中,您将QuerySnapshot分配给名为doc
的变量,然后显然假设它是DocumentSnapshot类型的对象,这是失败的
您需要调整代码以处理QuerySnapshot而不是DocumentSnapshot。请参考文档以了解对集合的查询返回的内容。特别要注意的是,来自查询的文档匹配列表可以在属性中作为对象查看。对集合执行查询时,可能有多个文档与条件匹配。因此,查询返回一个
QuerySnapshot
,其中包含匹配的文档。您需要在QuerySnapshot
上循环以获取各个文档:
self.dbManager.collection('test').where('entry_date', '==','2018-06-29').where('entry_status','==','active').get().then( async querySnapshot => {
querySnapshot.forEach(doc => {
console.log("doc--------->",doc.data());
});
});
请注意,在中已经很好地介绍了这一点,我建议这样做,因为查询功能构建在这一点之上