I can only see this possibly occurring under a condition like this:
{ "like": 1, "id": 3, "val": 7 },
{ "like": 1, "id": 3, "val": 7 },
{ "like": 2, "id": 3, "val": 5 },
{ "like": 2, "id": 2, "val": 5 },
And then in aggregate:
db.collection.aggregate([
{ "$group": {
"_id": "$like",
"id": { "$push": "$id" },
"val": { "$max": "$val" }
}},
{ "$project": {
"_id": "$id",
"val": 1
}}
])
Which gives:
{ "_id" : [ 3, 2 ], "val" : 5 }
{ "_id" : [ 3, 3 ], "val" : 7 }
For which we come down to, the $all condition is basically considered as a "set" just as $in is. And that means [3,3] is basically reduced to 3. Therefore if you want an "explicit" match then please do so:
db.collection.aggregate([
{ "$group": {
"_id": "$like",
"id": { "$push": "$id" },
"val": { "$max": "$val" }
}},
{ "$project": {
"_id": "$id",
"val": 1
}},
{ "$match": {
"_id": [3,3]
}}
])
_idcannot be an array.