Javascript 我可以在firestore中查询嵌套文档值吗?
我希望在firestore中搜索以下数据: 收集->文件->{日期{月份:10,年份:2017}Javascript 我可以在firestore中查询嵌套文档值吗?,javascript,google-cloud-firestore,Javascript,Google Cloud Firestore,我希望在firestore中搜索以下数据: 收集->文件->{日期{月份:10,年份: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.lo
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);
});
上面的伪代码不起作用。有什么建议吗 看起来您正在查询文档:
var ref = db.collection(collection).doc(document)
相反,您应该查询您的:
您的查询将在集合中的文档数组中选取满足“date.month==10”条件的所有文档
此外,我认为您必须更改解析来自.get()的数据的方式,因为它将是一个数组:
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
console.log(doc.id, " => ", doc.data());
});
})
这也应该有助于获得想法
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
console.log(doc.id, " => ", doc.data());
});
})