0

I'm trying to get all documents that their health is less than their maxHealth but I don't find any success and I don't find any information online, please assist.

This is the code I used

/**
 * query: The query in MQL.
 */
{
  health: {
    $lt: '$maxHealth'
  }
}

enter image description here

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Asaf
  • 949
  • 2
  • 13
  • 14
  • Try comparing the two fields in the `$match` stage using the [$expr](https://docs.mongodb.com/v4.2/reference/operator/query/expr/index.html) operator. – prasad_ Nov 25 '20 at 02:15
  • Can you give me an example? I couldn't find a way – Asaf Nov 25 '20 at 14:49
  • [MongoDb query condition on comparing 2 fields](https://stackoverflow.com/questions/4442453/mongodb-query-condition-on-comparing-2-fields). Note the two fields are within the same document. – prasad_ Nov 26 '20 at 02:55

0 Answers0