I'm trying to find all documents where an array's size is equal to a field's value. For example:
This document should be found:
{
arr: ["one", "two", "three"],
expected: 3
}
But not this one:
{
arr: ["one", "two", "three", "four"],
expected: 2
}
I'm assuming I have to use some form of aggregation, so I've decided to use $expr
:
$expr: { $eq: [{ $size: "$arr" }, { ??? }] }