every one.
I would like to know if it’s possible in mongodb to query only round number.
I have a collection where my documents have a field: amount and this field is a number.
But I would like to get only documents where fields is a round number.
so I saw there is a $round
but this round the number and I want only round number not rounded 😛
Does anyone if you can do that with query in mongodb ?
thanks a lot
2
Answers
You can use a tolerance to do something like this:
See how it works on the playground example
*EDIT: The
$round
here is a fix by @rickhg12hs to my former$floor
. Thanks!I would use $mod (num % 1) and check that the value is 0, like so:
Mongo Playground