summaryrefslogtreecommitdiff
path: root/jstests/geo_s2nearwithin.js
blob: bf289ef191ecfa674fc5f9cb749d52eb5e54d67c (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
// Test geoNear + $within.
t = db.geo_s2nearwithin
t.drop();

points = 10
for (var x = -points; x < points; x += 1) {
    for (var y = -points; y < points; y += 1) {
        t.insert({geo: [x, y]})
    }
}

t.ensureIndex({ geo : "2dsphere" })

// So, this is kind of messed-up.  The math for $within assumes a plane, but
// 2dsphere is spherical.  And yet...it still works, though it's inconsistent.
// TODO(hk): clarify this all.  :)
resNear = db.runCommand({geoNear : t.getName(), near: [0, 0], query: {geo: {$within: {$center: [[0, 0], 1]}}}})
assert.eq(resNear.results.length, 5)
resNear = db.runCommand({geoNear : t.getName(), near: [0, 0], query: {geo: {$within: {$center: [[0, 0], 0]}}}})
assert.eq(resNear.results.length, 1)
resNear = db.runCommand({geoNear : t.getName(), near: [0, 0], query: {geo: {$within: {$center: [[1, 0], 0.5]}}}})
assert.eq(resNear.results.length, 1)
resNear = db.runCommand({geoNear : t.getName(), near: [0, 0], query: {geo: {$within: {$center: [[1, 0], 1.5]}}}})
assert.eq(resNear.results.length, 9)