Let\'s assume I have a collection with documents with a ratio attribute that is a floating point number.
{\'ratio\':1.437}
How do I write a
I have another idea, but very tricky and need to change your data structure.
You can use geolocation index which supported by mongodb
First, change your data to this structure and keep the second value with 0
{'ratio':[1.437, 0]}
Then you can use $near
operator to find the the closest ratio value, and because the operator return a list sorted by distance with the integer you give, you have to use limit
to get only the closest value.
db.places.find( { ratio : { $near : [50,0] } } ).limit(1)
If you don't want to do this, I think you can just use @JohnnyHK's answer :)