I have those documents :
{"_id" : 1, "actors" : [{"matricule" : "AVB", "name":"XXX"}, {"matricule" : "AVB", "name":"YYY"}]}
{"_id" : 2, "actors" : [{"matricule" : "PMH", "name":"FFF"}, {"matricule" : "BNG", "name":"HHH"}]}
I would like to get only the first document because it’s the same matricule but a different name.
I use this query :
{
$expr:{$eq:["$actors.0.matricule", "$actors.1.matricule"]}
}
But it doesn’t work, I don’t have any results.
Do you know why ?
2
Answers
Try to use
$arrayElemAt
Here is the Mongo playground for your reference.
Query
*can work if you have one or many members inside the actors array
Playmongo