After I filtered nested array values then I added "$project" query for selecting specific fields.
I want to get "new_yn" field values outside of the nested array but I only got id and nested array values.
How can I fix my Query? Would you give me some guides? (MongoDB version is 5.0.6 Community)
[Query]
db.collection.aggregate([
{
$match: {
"new_yn": "Y",
"port_info": {
$elemMatch: {
"port_code": "http_https"
}
}
}
},
{
$project: {
port_info: {
$filter: {
input: "$port_info",
as: "item",
cond: {
$eq: [
"$$item.port_code",
"http_https"
]
}
}
}
}
},
{
"$project": {
"_id": 1,
"new_yn": 1,
"port_info.ip_port": 1
}
}
])
[Mongo Playground]