我可以在Firestore中查询嵌套的文档值吗? [英] Can I query a nested document value in firestore?
本文介绍了我可以在Firestore中查询嵌套的文档值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在搜索Firestore中的以下数据:集合->文档-> {日期{月:10,年:2017}}
I'm looking to do a search on the following data in firestore: Collection->Document->{date{month:10,year:2017}}
var ref = db.collection(collection).doc(document)
ref.where('date.month', '==', 10).get().then(doc=>{
if (!doc.exists) {
console.log('No such document!');
} else {
console.log('Document data:', doc.data());
}
}).catch(err => {
console.log('Error getting document', err);
});
上面的伪代码不起作用.有什么建议么?
The above pseudo code does not work. Any suggestions?
推荐答案
您似乎在查询文档:
var ref = db.collection(collection).doc(document)
相反,您应该查询您的收藏:
In stead you should be querying your collection:
var ref = db.collection(collection)
您的查询将在您的集合中的文档数组中拾取所有符合"date.month == 10"标准的文档.
Your query will pick up all documents, which meet "date.month==10" criteria among array of documents in your collection.
我还认为您必须更改解析来自.get()的数据的方式,因为它将成为数组:
Also I think you have to change how you parse the data coming from .get() because it's going to be an array:
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
console.log(doc.id, " => ", doc.data());
});
})
此链接应该有助于理解这个想法.
This link should be also helpful to get the idea.
这篇关于我可以在Firestore中查询嵌套的文档值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文