2017-08-02 58 views
0

如何编写一个查询,返回名为“address”的NoSQL数据库中的“每个”对象? ...请注意它可能会“嵌套”到其他对象。返回MongoDB中的每个对象

我试图

.find({ 
 
    'result.extractorData.data[0].group[0].address': { 
 
    $exists: true 
 
    } 
 
});

但没有工作,BTW数据的模样:

enter image description here

回答

0

我觉得嵌套数组您更好地使用elemMatch运营商

查看类似的问题herehere

的$ elemMatch运营商匹配包含与所有指定查询条件匹配的至少一个元素的数组字段的文件。

更多关于elemMatch

也是另一种方式,您可以:

.find({ 
    'result.extractorData.data.group.address': { 
    $exists: true 
    } 
}); 
+0

任何的例子吗? – Microsmsm

+0

@Microsmsm更新回答谢谢 – Tim

+0

没有按预期工作 – Microsmsm