MongoDB: How to get N decimals precision in a query

前端 未结 4 800
庸人自扰
庸人自扰 2021-01-25 04:58

Given the following documents in a MongoDB collection...

{ \"_id\": 1, \"amount\": { \"value\": 1.123456789999, \"rate\": 1.2 }}
{ \"_id\": 2, \"amount\": { \"va         


        
4条回答
  •  抹茶落季
    2021-01-25 05:04

    Starting from the answer I got from user3100115, here below is the final soluton:

    db.orders.find({ "$where": function() { return this.amount.value - (this.amount.value % 0.01) === 0.03; }})
    

    I hope it helps.

提交回复
热议问题