0

I have a document that looks like this:

{
    "total": 150.00,
    "products": [
        {"a": 75.00},
        {"b": 75.00}
    ],
    "paid": 100.00
}

I'm trying to find a way to query a document where the total is greater than the paid field.

So far I've tried:

db.find(...)

{paid: {$lt: "$total"}}
{paid: {$lt: "$total"}}
{paid: {$lt: "$$this.total"}}

{total: {$gt: "$paid"}}
{total: {$gt: "$$this.paid"}}

{$where: "this.total > this.paid"}

turivishal
  • 34,368
  • 7
  • 36
  • 59
Johnnes Souza
  • 361
  • 1
  • 8
  • 22

1 Answers1

0

You need to use $expr expression operator to match internal fields and $gt aggregation operator to check condition,

{ $expr: { $gt: ["$total", "$paid"] } }
turivishal
  • 34,368
  • 7
  • 36
  • 59