首先请将问题的标题改为适当的标题 - 我很难找到下面问题的简短描述性标题。
假设我有一份文件清单,如下所示:
[
cdate: { $date: ""2015-09-15T05:53:04.656Z" },
factor1: "aaa",
factor2: "bbb",
extra_info: [
{ host: "ex.com", int_value: 10 },
{ host: "ms.com", int_value: 20 },
{ host: "apple.com", int_value: 5 },
..
]
]
extra_info
数组大小各不相同。我需要所有文件 factor1 ="某些内容" , factor2 ="其他内容" extra_info 的阵列主机之一应该等于" ms.com" 。结果应显示为:
[
cdate: { $date: ""2015-09-15T05:53:04.656Z" },
factor1: "something",
factor2: "something else",
host: "ms.com",
int_value: 5
],
[
cdate: { $date: ""2015-09-14T08:17:32.123Z" },
factor1: "something",
factor2: "something else",
host: "ms.com",
int_value: 14
],
...
问题是如何做到这一点?
一种方法是,我可以获取所有文档,然后手动过滤掉 extra_info 数组,只留下我需要的值,但有没有办法在一个查询下粘贴它?