diff options
Diffstat (limited to 'jstests/core/geo9.js')
-rw-r--r-- | jstests/core/geo9.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/jstests/core/geo9.js b/jstests/core/geo9.js new file mode 100644 index 00000000000..8b6510f03b5 --- /dev/null +++ b/jstests/core/geo9.js @@ -0,0 +1,28 @@ + +t = db.geo9 +t.drop(); + +t.save( { _id : 1 , a : [ 10 , 10 ] , b : [ 50 , 50 ] } ) +t.save( { _id : 2 , a : [ 11 , 11 ] , b : [ 51 , 52 ] } ) +t.save( { _id : 3 , a : [ 12 , 12 ] , b : [ 52 , 52 ] } ) + +t.save( { _id : 4 , a : [ 50 , 50 ] , b : [ 10 , 10 ] } ) +t.save( { _id : 5 , a : [ 51 , 51 ] , b : [ 11 , 11 ] } ) +t.save( { _id : 6 , a : [ 52 , 52 ] , b : [ 12 , 12 ] } ) + +t.ensureIndex( { a : "2d" } ) +t.ensureIndex( { b : "2d" } ) + +function check( field ){ + var q = {} + q[field] = { $near : [ 11 , 11 ] } + arr = t.find( q ).limit(3).map( + function(z){ + return Geo.distance( [ 11 , 11 ] , z[field] ); + } + ); + assert.eq( 2 * Math.sqrt( 2 ) , Array.sum( arr ) , "test " + field ); +} + +check( "a" ) +check( "b" ) |