Mongodb 如何在反应式mongo中查询BigDecimal的类似查询
我使用的是ReactiveMongo,我想创建一个查询,它的性能类似于MongoDB中的数字查询(BigDecimal)。例如:像Mongodb 如何在反应式mongo中查询BigDecimal的类似查询,mongodb,scala,reactivemongo,Mongodb,Scala,Reactivemongo,我使用的是ReactiveMongo,我想创建一个查询,它的性能类似于MongoDB中的数字查询(BigDecimal)。例如:像4321.3456这样的整数应该与4321.34匹配 以下2个查询在MongoShell上实现了这一点: db.employee.find({"$where":"/^4321.34.*/.test(this.salary)"}) db.collection.find({ "$where": function() { return Ma
4321.3456
这样的整数应该与4321.34
匹配
以下2个查询在MongoShell上实现了这一点:
db.employee.find({"$where":"/^4321.34.*/.test(this.salary)"})
db.collection.find({
"$where": function() {
return Math.round(this.salary * 100)/ 100 === 1.12;
}
})
但是,我找不到使用ReactiveMongo执行此查询的方法
如何使用ReactiveMongo执行此类查询
更新
我试过以下的问题
val filter=Json.obj("$where" -> """/^4321.34.*/.test(this.salary)"""))
collection.find(filter).cursor[JsObject]()
在我的例子中,我确信我将只得到小数点后的2位数字,所以我做了如下范围查询
val lowerLimit = 4321.34
val upperLimit = lowerLimit + 0.01
val filter = Json.obj("$gte" -> JsNumber(lowerLimit),"$lt" -> JsNumber(upperLimit)))
collection.find(filter).cursor[JsObject]()
只有当我们确定只发送小数部分后的两位数字时,上述查询才有效。如果发送小数点后的三位数字,我们必须执行
val upperLimit=lowerLimit+0.001
您已经尝试了什么?@cchantep我已经更新了我的question@cchantep我再次更新了我的问题,它没有定义在此类查询中传递某些JavaScript表达式的方法。使用BSON序列化,可以尝试。