Skip to content
Snippets Groups Projects
Commit 6db38481 authored by mdalton's avatar mdalton
Browse files

Change mongodb near query so that a nil radius omits the maxDistance instead of setting to 0.0

parent ecbcf70b
No related branches found
No related tags found
No related merge requests found
......@@ -31,8 +31,11 @@ module Geocoder::Store
field = geocoder_options[:coordinates]
conds[field] = empty.clone
conds[field]["$nearSphere"] = coords.reverse
conds[field]["$maxDistance"] = \
Geocoder::Calculations.distance_to_radians(radius, options[:units])
if radius
conds[field]["$maxDistance"] = \
Geocoder::Calculations.distance_to_radians(radius, options[:units])
end
if obj = options[:exclude]
conds[:_id.ne] = obj.id
......
......@@ -36,4 +36,11 @@ class MongoidTest < Test::Unit::TestCase
result = PlaceWithoutIndex.index_options.keys.flatten[0] == :coordinates
assert !result
end
def test_nil_radius_omits_max_distance
location = [40.750354, -73.993371]
p = Place.near(location, nil)
key = Mongoid::VERSION >= "3" ? "location" : :location
assert_equal nil, p.selector[key]['$maxDistance']
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment