2017-08-02 44 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