Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我可以在firestore中查询嵌套文档值吗?_Javascript_Google Cloud Firestore - Fatal编程技术网

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

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

我希望在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.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());
        });
    })