I have several JSON like the one below and I need to chek all of them that have the properties "name" and "skd" duplicates as shown.
{
"_id" : ObjectId("65498654654"),
"name": "Orden",
"__v" : 0,
"inventory" : [
{
"name" : "firstElement",
"skd" : "9879",
"name" : "AnotherfirstElement1",
"skd" : "32197",
},
{
"name" : "secondElement",
"skd" : "321654",
},
{
"name" : "thirdElement",
"skd" : "321654"
}
]
}
I tried this but not working
db.mycollection.aggregate([
{ $unwind: "$inventory" },
{
$group: {
_id: {
_id: "$_id",
names: "$inventory.name"
},
sum: { $sum: 1 }
}
},
{ $match: { sum: { $gt: 1 } } }
])
I expect something to show me that position 0 has the duplicate properties.