diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-02-23 10:41:07 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-02-23 10:41:07 -0500 |
commit | fd3a8e76e55678b42d654c908f87bee8ca572974 (patch) | |
tree | 9400d51be524a3ccb5665285c7d76f75d0e9070e /jstests/geo3.js | |
parent | 221301072d101fdd17134ded5f6267958d6de05b (diff) | |
download | mongo-fd3a8e76e55678b42d654c908f87bee8ca572974.tar.gz |
2d gis index
Diffstat (limited to 'jstests/geo3.js')
-rw-r--r-- | jstests/geo3.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/jstests/geo3.js b/jstests/geo3.js new file mode 100644 index 00000000000..6403c0e3a5c --- /dev/null +++ b/jstests/geo3.js @@ -0,0 +1,39 @@ + +t = db.geo3 +t.drop(); + +n = 1 +for ( var x=-100; x<100; x+=2 ){ + for ( var y=-100; y<100; y+=2 ){ + t.insert( { _id : n++ , loc : [ x , y ] , a : Math.abs( x ) % 5 , b : Math.abs( y ) % 5 } ) + } +} + +t.ensureIndex( { loc : "2d" } ) + +fast = db.runCommand( { geo2d : t.getName() , near : [ 50 , 50 ] , num : 10 } ); +slow = db.runCommand( { geo2d : t.getName() , near : [ 50 , 50 ] , num : 10 , start : "11" } ); + +assert.lt( fast.stats.nscanned * 10 , slow.stats.nscanned , "A1" ); +assert.lt( fast.stats.objectsLoaded , slow.stats.objectsLoaded , "A2" ); +assert.eq( fast.stats.avgDistance , slow.stats.avgDistance , "A3" ); +//printjson( fast.stats ); + +// test filter + +filtered1 = db.runCommand( { geo2d : t.getName() , near : [ 50 , 50 ] , num : 10 , query : { a : 2 } } ); +assert.eq( 10 , filtered1.results.length , "B1" ); +filtered1.results.forEach( function(z){ assert.eq( 2 , z.obj.a , "B2: " + tojson( z ) ); } ) +//printjson( filtered1.stats ); + +t.dropIndex( { loc : "2d" } ) +t.ensureIndex( { loc : "2d" , a : 1 } ) + +filtered2 = db.runCommand( { geo2d : t.getName() , near : [ 50 , 50 ] , num : 10 , query : { a : 2 } } ); +assert.eq( 10 , filtered2.results.length , "B3" ); +filtered2.results.forEach( function(z){ assert.eq( 2 , z.obj.a , "B4: " + tojson( z ) ); } ) +//printjson( filtered2.stats ); + +assert.eq( filtered1.stats.avgDistance , filtered2.stats.avgDistance , "C1" ) +assert.eq( filtered1.stats.nscanned , filtered2.stats.nscanned , "C3" ) +assert.gt( filtered1.stats.objectsLoaded , filtered2.stats.objectsLoaded , "C3" ) |