We need to push/addtoset only if the key in the document ne []
How do we achieve this
{
"_id" : ObjectId("xxxxxx"),
"shop" : "REQ4",
"bolt" : "5647",
"nut" : "1111",
}
{
"_id" : ObjectId("xxxxxx"),
"shop" : "REQ4",
"bolt" : "2314",
"nut":[]
}
Aggregates.group("$shop", Accumulators.addToSet("bolt", "$bolt"),Accumulators.addToSet("nut", "nut"))//only if nut ne []
Expected output:
{ "_id" : "REQ4", "bolt" : ["5647", "2314"], "nut" : ["1111"]