我可以在firestore中查询嵌套的文档值吗?

我可以在firestore中查询嵌套的文档值吗?

问题描述:

我希望做对公司的FireStore以下数据的搜索: 系列 - >文件 - > {日期{月:10年:2017年}}我可以在firestore中查询嵌套的文档值吗?

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) 

在代替你应该询问你的collection

var ref = db.collection(collection) 

您的查询将拿起所有文件,符合“date.month您的集合中的文档数组中的“== 10”条件。

此外我认为你必须改变你如何解析从获得()来,因为这将是一个数组中的数据:

.then(function(querySnapshot) { 
     querySnapshot.forEach(function(doc) { 
      console.log(doc.id, " => ", doc.data()); 
     }); 
    }) 

link也应该是有帮助的得到的想法。