Struggling with setting up a query that involves an array of objects within a specific index. My Schema includes a field that consists of an array of objects:
{userID: ObjectID, someArray: [{foo: "bar"},{bar: "foo"}]}
I am interested in retrieving records where the first element in SomeArray contains a non-empty object or where someArray does not have null values.
I attempted to use:
db.find({someArray: {$exists: true, $not: {$size: 0}} })
However, someArray sometimes includes null objects, rendering this approach ineffective. As a last resort, I could cache the entire collection and filter using raw JavaScript, although this might not be the most efficient method.