How to compare two fields in subdocuments within an array

How can I match a document whose property A - an array of embedded documents - includes one such as subDocument.propertyX < subDocument.propertyY? Tried:

'A': {
    $elemMatch: {
        propertyX: {
            $lt: '$propertyY',


Hello @Joao_Teixeira1 ,

Welcome to The MongoDB Community Forums! :wave:

Can you please share additional details for me to understand your use case better?

  • MongoDB Version used
  • Sample documents
  • Expected output document/documents