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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
// multiple geo clauses with $or
t = db.geoor;
t.drop();
var p = [-71.34895, 42.46037];
var q = [1.48736, 42.55327];
t.save({loc: p});
t.save({loc: q});
var indexname = "2dsphere";
t.ensureIndex({loc: indexname});
assert.eq(1, t.find({loc: p}).itcount(), indexname);
// $or supports at most one $near clause
assert.eq(2,
t.find({$or: [{loc: {$nearSphere: p}}]}).itcount(),
'geo query not supported by $or. index type: ' + indexname);
assert.throws(function() {
assert.eq(2,
t.find({$or: [{loc: {$nearSphere: p}}, {loc: {$nearSphere: q}}]}).itcount(),
'geo query not supported by $or. index type: ' + indexname);
}, null, '$or with multiple $near clauses');
// the following tests should match the points in the collection
assert.eq(2,
t.find({
$or: [
{loc: {$geoWithin: {$centerSphere: [p, 10]}}},
{loc: {$geoWithin: {$centerSphere: [p, 10]}}}
]
}).itcount(),
'multiple $geoWithin clauses not supported by $or. index type: ' + indexname);
assert.eq(
2,
t.find({
$or: [
{loc: {$geoIntersects: {$geometry: {type: 'LineString', coordinates: [p, q]}}}},
{
loc: {
$geoIntersects:
{$geometry: {type: 'LineString', coordinates: [[0, 0], [1, 1]]}}
}
}
]
}).itcount(),
'multiple $geoIntersects LineString clauses not supported by $or. index type: ' + indexname);
assert.eq(2,
t.find({
$or: [
{loc: {$geoIntersects: {$geometry: {type: 'Point', coordinates: p}}}},
{loc: {$geoIntersects: {$geometry: {type: 'Point', coordinates: q}}}}
]
}).itcount(),
'multiple $geoIntersects Point clauses not supported by $or. index type: ' + indexname);
assert.eq(
2,
t.find({
$or: [
{
loc: {
$geoIntersects:
{$geometry: {type: 'Polygon', coordinates: [[[0, 0], p, q, [0, 0]]]}}
}
},
{
loc: {
$geoIntersects: {
$geometry:
{type: 'Polygon', coordinates: [[[0, 0], [1, 1], [0, 1], [0, 0]]]}
}
}
}
]
}).itcount(),
'multiple $geoIntersects Polygon clauses not supported by $or. index type: ' + indexname);
t.dropIndexes();
var indexname = "2d";
t.ensureIndex({loc: indexname});
assert.eq(2,
t.find({
$or: [
{loc: {$geoWithin: {$centerSphere: [p, 10]}}},
{loc: {$geoWithin: {$centerSphere: [p, 10]}}}
]
}).itcount(),
'multiple $geoWithin clauses not supported by $or. index type: ' + indexname);
|