Created
November 18, 2010 15:00
-
-
Save jacquescrocker/705082 to your computer and use it in GitHub Desktop.
test case for 1.6.4 geospatial indexing bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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