更新时间:2023-01-17 15:00:13
您可以在下面的汇总查询中进行尝试.
You can try below aggregation query.
$filter
内部数组和$arrayElemAt
来投影匹配的元素.
$filter
inner array and $arrayElemAt
to project the matched element.
$map
可在所有Kamadas中输出所有匹配的Speletajs元素.
$map
to output all matching Speletajs elements across all Kamadas.
$arrayElemAt
减少为单个匹配项.对于多个匹配项,请删除$arrayElemAt
.
$arrayElemAt
to reduce to a single match. For multiple matches remove $arrayElemAt
.
db.games.aggregate([
{"$match":{"Spele.Komanda.Speletaji.Speletajs.Nr":16}},
{"$project":{
"Speletaji":{
"$arrayElemAt":[
{"$map":{
"input":"$Spele.Komanda",
"in":{
"$arrayElemAt":[
{"$filter":{
"input":"$$this.Speletaji.Speletajs",
"cond":{"$eq":["$$this.Nr",16]}
}},
0]
}
}},
0]
}
}}
])