Skip to content

Instantly share code, notes, and snippets.

@jacquescrocker
Created November 18, 2010 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacquescrocker/705082 to your computer and use it in GitHub Desktop.
Save jacquescrocker/705082 to your computer and use it in GitHub Desktop.
test case for 1.6.4 geospatial indexing bug
# REPRO for Geospatial Indexing bug introduced in 1.6.4 (RC0).
# this works in MongoDB 1.6.3. But not in 1.6.4
require 'test/unit'
require 'mongo'
class TestBugRepro < Test::Unit::TestCase
def setup
# customize this connection if needed
connection = Mongo::Connection.new
puts "You are using MongoDB: #{connection.server_info['version']} (ruby driver #{Mongo::VERSION})"
@tiles = connection.db("mongodb-repro")["tiles"]
# clear existing data
@tiles.drop
# add some test data (on the x axis)
@tiles.insert([{"letter"=>"S", "position"=>[-3, 0]}])
@tiles.insert([{"letter"=>"C", "position"=>[-2, 0]}])
@tiles.insert([{"letter"=>"R", "position"=>[-1, 0]}])
@tiles.insert([{"letter"=>"A", "position"=>[0, 0]}])
@tiles.insert([{"letter"=>"B", "position"=>[1, 0]}])
@tiles.insert([{"letter"=>"B", "position"=>[2, 0]}])
@tiles.insert([{"letter"=>"L", "position"=>[3, 0]}])
@tiles.insert([{"letter"=>"E", "position"=>[4, 0]}])
end
# this works
def test_geospatial_without_min_max
@tiles.create_index([[:position, Mongo::GEO2D]])
# run geospacial query
result = @tiles.find({"position"=>{"$within"=> {"$box"=>[[-3, -1], [0, 1]]} }})
assert_equal(4, result.count)
end
# this works
def test_geospatial_with_min_max
@tiles.create_index([[:position, Mongo::GEO2D]], :min=>-10_000_000, :max=>10_000_000)
# run geospacial query
result = @tiles.find({"position"=>{"$within"=> {"$box"=>[[-3, -1], [0, 1]]} }})
assert_equal(4, result.count)
end
# this doesnt
def test_geospatial_with_min_max_big
@tiles.create_index([[:position, Mongo::GEO2D]], :min=>-100_000_000, :max=>100_000_000)
# run geospacial query
result = @tiles.find({"position"=>{"$within"=> {"$box"=>[[-3, -1], [0, 1]]} }})
assert_equal(4, result.count)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment