summaryrefslogtreecommitdiff
path: root/jstests/core/geo_haystack3.js
blob: 1357ccf4f511a5a31da78ccc05c55bfabcbd021c (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
54
t = db.geo_haystack3;
t.drop();

//
// Tests for geo haystack validity
//

t.insert({pos: "invalid"});
assert.commandFailed(t.ensureIndex({pos: "geoHaystack", type: 1}, {bucketSize: 1}));
t.drop();

t.insert({pos: []});
assert.commandFailed(t.ensureIndex({pos: "geoHaystack", type: 1}, {bucketSize: 1}));
t.drop();

t.insert({pos: [1, 2]});
assert.commandWorked(t.ensureIndex({pos: "geoHaystack", type: 1}, {bucketSize: 1}));
t.drop();

t.insert({pos: {x: 1, y: 2}});
assert.commandWorked(t.ensureIndex({pos: "geoHaystack", type: 1}, {bucketSize: 1}));
t.drop();

t.insert({pos: {x: 1, y: 2, z: 3}});
assert.commandWorked(t.ensureIndex({pos: "geoHaystack", type: 1}, {bucketSize: 1}));
t.drop();

//
// Tests for geo haystack search
//

t.insert({pos: {long: 34, lat: 33}});
t.insert({pos: {long: 34.2, lat: 33.3}, type: ["bar", "restaurant"]});
t.insert({pos: {long: 34.2, lat: 37.3}, type: ["bar", "chicken"]});
t.insert({pos: {long: 59.1, lat: 87.2}, type: ["baz", "office"]});
t.ensureIndex({pos: "geoHaystack", type: 1}, {bucketSize: 1});

// This only matches the first insert.  What do we want?  First 3 or just the first?
res = t.runCommand("geoSearch", {near: [33, 33], maxDistance: 6, search: {}, limit: 30});
assert.eq(1, res.stats.n, "Right # of matches");
assert.eq(34, res.results[0].pos.long, "expected longitude");
assert.eq(33, res.results[0].pos.lat, "expected latitude");

// This matches the middle 2 of the 4 elements above.
res = t.runCommand("geoSearch", {near: [33, 33], maxDistance: 6, search: {type: "bar"}, limit: 2});
assert.eq(2, res.stats.n, "Right # of matches");
assert.eq("bar", res.results[0].type[0], "expected value for type");
assert.eq("bar", res.results[1].type[0], "expected value for type");
assert.neq(res.results[0].type[1], res.results[1].type[1], "should get 2 diff results");

// This is a test for the limit being reached/only 1 returned.
res = t.runCommand("geoSearch", {near: [33, 33], maxDistance: 6, search: {type: "bar"}, limit: 1});
assert.eq(1, res.stats.n, "Right # of matches");
assert.eq("bar", res.results[0].type[0], "expected value for type");