I need to fetch the document from the db, data is as below
{
"systemName": "ABC",
"systemUsageAttrs" : [
{
"cpuUsage": 30,
"memUsage": 40,
"isActive": false
},
{
"cpuUsage": 88.2,
"memUsage": 33.5,
"isActive": false
}
]
},
{
"systemName": "DEF",
"systemUsageAttrs" : [
{
"cpuUsage": 30,
"memUsage": 40,
"isActive": false
},
{
"cpuUsage": 88.2,
"memUsage": 33.5,
"isActive": true
}
]
},
{
"systemName": "GHI",
"systemUsageAttrs" : [
{
"cpuUsage": 30,
"memUsage": 40,
"isActive": true
},
{
"cpuUsage": 88.2,
"memUsage": 33.5,
"isActive": true
}
]
}
I have used below piece of code, but it returns 2 documents instead of one.
List<Document> systemDetailsAL = sysUsageDetailsColl.aggregate(
asList(
unwind("$systemUsageAttrs"),
match(eq("systemUsageAttrs.isActive",false)),
group("$_id", Accumulators.first("systemName","$systemName"),
Accumulators.push("systemUsageAttrs", "$systemUsageAttrs")),
project(Projections.fields(Projections.excludeId()))
)
).into(new ArrayList<Document>());
Above code also provides the document which has isActive:false for one of the elements in the array.
Expected output is Document with systemName: ABC, since it has isActive:false in all the elements of array.
Any help/pointers appreciated.