summaryrefslogtreecommitdiff
path: root/jstests/core/geo_oob_sphere.js
blob: 08a10758c77f88d60063775754894ce59b621c44 (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
//
// Ensures spherical queries report invalid latitude values in points and center positions
//
(function() {
"use strict";

const coll = db.geooobsphere;
coll.drop();

assert.commandWorked(coll.insert({loc: {x: 31, y: 89}}));
assert.commandWorked(coll.insert({loc: {x: 30, y: 89}}));
assert.commandWorked(coll.insert({loc: {x: 30, y: 89}}));
assert.commandWorked(coll.insert({loc: {x: 30, y: 89}}));
assert.commandWorked(coll.insert({loc: {x: 30, y: 89}}));
assert.commandWorked(coll.insert({loc: {x: 30, y: 89}}));
assert.commandWorked(coll.insert({loc: {x: 30, y: 91}}));

assert.commandWorked(coll.createIndex({loc: "2d"}));

assert.throws(function() {
    coll.find({loc: {$nearSphere: [30, 91], $maxDistance: 0.25}}).count();
});

assert.throws(function() {
    coll.find({loc: {$within: {$centerSphere: [[-180, -91], 0.25]}}}).count();
});

// In a spherical geometry, this point is out-of-bounds.
assert.commandFailedWithCode(coll.runCommand("find", {filter: {loc: {$nearSphere: [179, -91]}}}),
                             17444);
assert.commandFailedWithCode(coll.runCommand("aggregate", {
    cursor: {},
    pipeline: [{
        $geoNear: {
            near: [179, -91],
            distanceField: "dis",
            spherical: true,
        }
    }]
}),
                             17444);
}());