填充具有以下结果。
User.find({})
.exists('thumbnail', true)
.select('thumbnail nickname')
.populate({
path: 'portfolios',
select: 'tag category',
})
结果
[
{
"portfolios": [
{
"_id": "5e10812d27a2a8c267e86bd1",
"category": "222",
"tag": "1"
},
{
"_id": "5e10812527a2a8c267e86bd0",
"category": "111",
"tag": "2"
}
],
"_id": "5e109d3859c976ce223f92c6",
"nickname": "ABC",
"thumbnail": "ABC"
},
{
"portfolios": [
{
"_id": "5e10812d27a2a8c267e86bd1",
"category": "222",
"tag": "2"
},
{
"_id": "5e10812527a2a8c267e86bd0",
"category": "111",
"tag": "3"
}
],
"_id": "5e109d3859c976ce223f92c6",
"nickname": "ABC",
"thumbnail": "ABC"
}
]
我想返回一个仅过滤具有特定标记值的对象的数组,如下所示:
仅标记为1
结果
[
{
"portfolios": [
{
"_id": "5e10812d27a2a8c267e86bd1",
"category": "222",
"tag": "1"
}
],
"_id": "5e109d3859c976ce223f92c6",
"nickname": "ABC",
"thumbnail": "ABC"
}
]
我知道我无法添加查询,因为选择后会发生填充。
我是否需要通过find结果处理与标签匹配的数据以获得我想要的结果?
我对此很好奇。