I have my collection as
Student
{
"first_name":"Harew",
"last_name":"Jackson",
"class":14,
"fee": [
{ "tuition":48500.2456, "transportation":500 }
]
}
I need to filter student according to fee = 4500.24
and it should display
all the students having fee 4500.24 ignoring other digits after the decimal point.
I have searched in MongoDB: How to get N decimals precision in a query
precision-in-a-query but the solution provided here does not work in my scenario since
"$mod": [ "$amount.value", 0.01 ]
is not applicable for BigDecimal
type and in my collection I have fee type as BigDecimal
.
The following solution seems to work well but I don't know how to implement this in Scala
db.collection.find({
"$where": function() {
return Math.round(this.fee.school * 100)/ 100 === 1.12;
}
})