Mongo field A greater than field B

后端 未结 4 987
渐次进展
渐次进展 2020-12-09 15:58

i\'m trying a simple query in Mongo which in MySQL would look like this.

select * from emails where bounceCount > sentCount;

So far I ha

4条回答
  •  轮回少年
    2020-12-09 16:33

    You can use the $where operator to do this, which lets you use Javascript code in the query.

    For your example, you would do:

    db.email.find({ $where: "this.bounceCount > this.sentCount" });
    

    See the MongoDB documentation page for more details on the $where operator: http://docs.mongodb.org/manual/reference/operator/where/#op._S_where

提交回复
热议问题