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?

4

2 回答 2

0

由于 MLab 提供了 Mongo 的最大 3.6 版本,因此您将哪个版本用于 MongoDB,因此您需要修改 Query 或升级 Mongo DB 版本。

于 2019-06-21T06:17:14.567 回答
0

我正在使用这个查询。

InvoiceModel.aggregate([
    {
      $expr:{'$gt': [ "$totalAmount", "$remainingDebt" ]}
    },
    {
      $count:'COUNT'
    }
 ],(error, result)=>{
   console.log(result)
})
于 2021-07-27T10:22:29.623 回答