summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/geo_mnypts.js
blob: bc7935fa7a65850b2e3a54409b9e4b1840e83a12 (plain)
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
// Test sanity of geo queries with a lot of points

var coll = db.testMnyPts
coll.drop()

var totalPts = 500 * 1000

// Add points in a 100x100 grid
var bulk = coll.initializeUnorderedBulkOp();
for( var i = 0; i < totalPts; i++ ){
    var ii = i % 10000
    bulk.insert({ loc : [ ii % 100, Math.floor( ii / 100 ) ] });
}
assert.writeOK(bulk.execute());

coll.ensureIndex({ loc : "2d" })

// Check that quarter of points in each quadrant
for( var i = 0; i < 4; i++ ){
    var x = i % 2
    var y = Math.floor( i / 2 )
    
    var box = [[0, 0], [49, 49]]
    box[0][0] += ( x == 1 ? 50 : 0 )
    box[1][0] += ( x == 1 ? 50 : 0 )
    box[0][1] += ( y == 1 ? 50 : 0 )
    box[1][1] += ( y == 1 ? 50 : 0 )

    assert.eq( totalPts / 4, coll.find({ loc : { $within : { $box : box } } }).count() )
    assert.eq( totalPts / 4, coll.find({ loc : { $within : { $box : box } } }).itcount() )

}

// Check that half of points in each half
for( var i = 0; i < 2; i++ ){
    
    var box = [[0, 0], [49, 99]]
    box[0][0] += ( i == 1 ? 50 : 0 )
    box[1][0] += ( i == 1 ? 50 : 0 )

    assert.eq( totalPts / 2, coll.find({ loc : { $within : { $box : box } } }).count() )
    assert.eq( totalPts / 2, coll.find({ loc : { $within : { $box : box } } }).itcount() )

}

// Check that all but corner set of points in radius
var circle = [[0, 0], (100 - 1) * Math.sqrt( 2 ) - 0.25 ]

assert.eq( totalPts - totalPts / ( 100 * 100 ), coll.find({ loc : { $within : { $center : circle } } }).count() )
assert.eq( totalPts - totalPts / ( 100 * 100 ), coll.find({ loc : { $within : { $center : circle } } }).itcount() )