I need to find all documents where an element of an array in that document matches a condition of it's fields:
{
doc_id: 0,
array_field: [
{ id: 0, min: 1, max: 2 },
{ id: 1, min: 1, max: 1 },
...
]
}
...
I need all documents where any object in array_field has a max != min.
I've been using $elemMatch to query the array elements (which works fine by itself), but I can't seem to make it work with an $expr:
{
array_field: {
$elemMatch: {
$expr: { $ne: [ "$min", "$max" ]}
}
}
}
How do I correctly compare the fields within the array object?