File: geog.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 (60 lines) | stat: -rw-r--r-- 1,290 bytes parent folder | download | duplicates (3)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Test geo index selection criterion, with and without explicit hints. SERVER-4531

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

t.save({a:{x:0,y:0},z:1});

query = {a:[0,0],z:1};

function assertCount( count, hint ) {
    if ( hint ) {
        assert.eq( count, t.find(query).hint(hint).itcount() );
    }
    else {
        assert.eq( count, t.find(query).itcount() );
        assert.eq( count, t.count(query) );
    }
}

function assertNotTryingGeoIndex() {
    plans = t.find(query).explain(true).allPlans;
    for( i in plans ) {
        assert( !plans[i].cursor.match( /Geo/ ) );
    }
}

function assertNonGeoResults() {
    assertCount( 0 );
    assertNotTryingGeoIndex();
}

function assertNonGeoResultsWithHint() {
    assertCount( 0, {a:1} );
    assertCount( 0, {$natural:1} );
}

function assertGeoResults() {
    assertCount( 1 );
}

function assertGeoResultsWithHint() {
    assertCount( 1, {a:'2d',z:1} );
}

assertNonGeoResults();

t.ensureIndex({a:'2d',z:1});
// If geo is the only index option, pick it.
assertGeoResults();
assertGeoResultsWithHint();

t.ensureIndex({a:1});
// If there is a non geo index, don't use the geo index.
assertNonGeoResults();
assertNonGeoResultsWithHint();
assertGeoResultsWithHint();

t.dropIndex({a:1});
assertGeoResults();
assertGeoResultsWithHint();