0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00
mongodb/jstests/geo_box1.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2010-03-16 13:48:24 +01:00
t = db.geo_box1;
t.drop();
2010-03-16 22:02:17 +01:00
num = 0;
for ( x=0; x<=20; x++ ){
for ( y=0; y<=20; y++ ){
o = { _id : num++ , loc : [ x , y ] }
t.save( o )
}
}
2010-03-16 13:48:24 +01:00
t.ensureIndex( { loc : "2d" } );
2010-03-16 22:02:17 +01:00
searches = [
[ [ 1 , 2 ] , [ 4 , 5 ] ] ,
[ [ 1 , 1 ] , [ 2 , 2 ] ] ,
[ [ 0 , 2 ] , [ 4 , 5 ] ] ,
2010-03-16 22:07:34 +01:00
[ [ 1 , 1 ] , [ 2 , 8 ] ] ,
2010-03-16 22:02:17 +01:00
];
2010-03-16 13:48:24 +01:00
2010-03-16 22:02:17 +01:00
for ( i=0; i<searches.length; i++ ){
b = searches[i];
//printjson( b );
2010-03-16 13:48:24 +01:00
2010-03-16 22:02:17 +01:00
q = { loc : { $within : { $box : b } } }
2010-03-16 22:07:34 +01:00
numWanetd = ( 1 + b[1][0] - b[0][0] ) * ( 1 + b[1][1] - b[0][1] );
2010-03-17 16:12:21 +01:00
assert.eq( numWanetd , t.find(q).itcount() , "itcount: " + tojson( q ) );
2010-03-16 22:07:34 +01:00
printjson( t.find(q).explain() )
2010-03-16 22:02:17 +01:00
}
2010-03-17 16:28:26 +01:00
assert.eq( 0 , t.find( { loc : { $within : { $box : [ [100 , 100 ] , [ 110 , 110 ] ] } } } ).itcount() , "E1" )
assert.eq( 0 , t.find( { loc : { $within : { $box : [ [100 , 100 ] , [ 110 , 110 ] ] } } } ).count() , "E2" )
2010-03-17 16:46:26 +01:00
2010-03-18 02:51:14 +01:00
assert.eq( num , t.find( { loc : { $within : { $box : [ [ 0 , 0 ] , [ 110 , 110 ] ] } } } ).count() , "E3" )
assert.eq( num , t.find( { loc : { $within : { $box : [ [ 0 , 0 ] , [ 110 , 110 ] ] } } } ).itcount() , "E4" )
assert.eq( 57 , t.find( { loc : { $within : { $box : [ [ 0 , 0 ] , [ 110 , 110 ] ] } } } ).limit(57).itcount() , "E5" )
2010-03-17 16:46:26 +01:00