I have this aggregation that I want to transform into a Spring MongoDb aggregation. A document has several named data in a list. But I want to project only 2 datas for a couple of documents with a given ID as follow.
How to put a filter in the spring aggregation ?
db.getCollection("data").aggregate(
[
{
"$match" : {
"_id" : {
"$in" : [
1,
2
]
}
}
},
{
"$project" : {
"datas" : {
"$filter" : {
"input" : "$datas",
"as" : "item",
"cond" : {
"$or" : [
{
"$eq" : [
"$$item.name",
"data1"
]
},
{
"$eq" : [
"$$item.name",
"data2"
]
}
]
}
}
}
}
}
]
);