'$elemMatch on array of objects

My schema has 6 attributes of type Array, which can each contain objects, like this:

alpha : Array
  0 : Object
    linkedID : "62495a66fb140b240476d8ff"
    verified : false
  1 : Object
    linkedID : "62494fd789291c4f58bdad86"
    verified : true
  ...

I want to write a query that returns a document where at least one of these Arrays contains an object that has the attribute verified == false. I've tried with $elemMatch:

myModel.findOne(
  {$or: [
    { alpha: { $elemMatch: { verified: false } } },
    { beta: { $elemMatch: { verified: false } } },
    { gamma: { $elemMatch: { verified: false } } },
    { delta: { $elemMatch: { verified: false } } },
    { epsilon: { $elemMatch: { verified: false } } },
    { zeta: { $elemMatch: { verified: false } } }
  ] }
)

But this didn't work. I think this may be because it's a nested object, but I have no idea how to solve this. I'd really appreciate any advice.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source