File: geo_box1.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (43 lines) | stat: -rw-r--r-- 1,236 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

t = db.geo_box1;
t.drop();

num = 0;
for ( x=0; x<=20; x++ ){
    for ( y=0; y<=20; y++ ){
        o = { _id : num++ , loc : [ x , y ] } 
        t.save( o )
    }
}

t.ensureIndex( { loc : "2d" } );

searches = [
    [ [ 1 , 2 ] , [ 4 , 5 ] ] ,
    [ [ 1 , 1 ] , [ 2 , 2 ] ] ,
    [ [ 0 , 2 ] , [ 4 , 5 ] ] ,
    [ [ 1 , 1 ] , [ 2 , 8 ] ] ,
];


for ( i=0; i<searches.length; i++ ){
    b = searches[i];
    //printjson( b );
    
    q = { loc : { $within : { $box : b } } }
    numWanetd = ( 1 + b[1][0] - b[0][0] ) * ( 1 + b[1][1] - b[0][1] );
    assert.eq( numWanetd  , t.find(q).itcount() , "itcount: " + tojson( q ) );
    printjson( t.find(q).explain() )
}



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" )


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" )