0

I tried finding solution for this online, but no success.

This is the code:

Invoice.count( { $expr: {$gt: [ "$totalAmount", "$remainingDebt" ]} } ).exec(callback);

where totalAmount and remainingDebt are fields in schema Invoice.

The result I get is: "unknown top level operator $expr".

I am using mongoose 5.0.11 and mongo lab.

Any ideas?

chridam
  • 100,957
  • 23
  • 236
  • 235
Nebojsa
  • 133
  • 1
  • 8
  • 2
    At the time of writing, the version of MongoDB that mLab uses by default is currently MongoDB version 3.4 yet [**`$expr`**](https://docs.mongodb.com/manual/reference/operator/query/expr/) is only available in 3.6 (and newer) versions. – chridam Mar 26 '18 at 21:45
  • Thank you @chridam... I was thinking that I made a mistake in query :/... – Nebojsa Mar 26 '18 at 22:21

2 Answers2

0

which version you are Using for the MongoDB since MLab is Providing the Maximum 3.6 version of the Mongo so you need to either modify the Query or upgrade the Mongo DB version.

hardik beladiya
  • 268
  • 2
  • 12
0

I'm use this query.

InvoiceModel.aggregate([
    {
      $expr:{'$gt': [ "$totalAmount", "$remainingDebt" ]}
    },
    {
      $count:'COUNT'
    }
 ],(error, result)=>{
   console.log(result)
})