I have a collection of diagrams. Each diagram has several blocks. And each block is having several ports, which in itself has multiple objects as fields.
So far i am only able to apply $filter or $group up to level 1 on blocks. I am unable to filter up to ports based on some condition.
The document structure is: Diagram
[
{
"_id": "1",
"blocks": [
{
"port": [
{
"portType": {
"function": "input"
}
}
]
}
]
}
]
What i am trying to achieve is to get a list of all ports which have input as portType.function from the collection
db.collection.aggregate([{$project:{"blocks.ports":{$filter:{input:"$blocks.ports",as:"ports",cond:{$in:["input","$$ports.portType.function"]}}}}}]);
Expected output : list<Ports> which have only portType.function as input.
Actual output: Returns all the documents which have at least one port as "input" along with all the other ports as well.