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
97
98
99
100
101
102
|
// @tags: [
// requires_fastcount,
// requires_non_retryable_writes,
// ]
//
// Test of sample big polygon functionality
//
var coll = db.geo_big_polygon;
coll.drop();
// coll.createIndex({ loc : "2dsphere" });
var bigCRS = {type: "name", properties: {name: "urn:x-mongodb:crs:strictwinding:EPSG:4326"}};
var bigPoly20 = {
type: "Polygon",
coordinates: [[[10.0, 10.0], [-10.0, 10.0], [-10.0, -10.0], [10.0, -10.0], [10.0, 10.0]]],
crs: bigCRS
};
var bigPoly20Comp = {
type: "Polygon",
coordinates: [[[10.0, 10.0], [10.0, -10.0], [-10.0, -10.0], [-10.0, 10.0], [10.0, 10.0]]],
crs: bigCRS
};
var poly10 = {
type: "Polygon",
coordinates: [[[5.0, 5.0], [5.0, -5.0], [-5.0, -5.0], [-5.0, 5.0], [5.0, 5.0]]]
};
var line10 = {
type: "LineString",
coordinates: [[5.0, 5.0], [5.0, -5.0], [-5.0, -5.0], [-5.0, 5.0], [5.0, 5.0]]
};
var centerPoint = {type: "Point", coordinates: [0, 0]};
var polarPoint = {type: "Point", coordinates: [85, 85]};
var lineEquator = {type: "LineString", coordinates: [[-20, 0], [20, 0]]};
assert.commandWorked(coll.insert({loc: poly10}));
assert.commandWorked(coll.insert({loc: line10}));
assert.commandWorked(coll.insert({loc: centerPoint}));
assert.commandWorked(coll.insert({loc: polarPoint}));
assert.commandWorked(coll.insert({loc: lineEquator}));
assert.eq(coll.find({}).count(), 5);
jsTest.log("Starting query...");
assert.eq(coll.find({loc: {$geoWithin: {$geometry: bigPoly20}}}).count(), 3);
assert.eq(coll.find({loc: {$geoIntersects: {$geometry: bigPoly20}}}).count(), 4);
assert.eq(coll.find({loc: {$geoWithin: {$geometry: bigPoly20Comp}}}).count(), 1);
assert.eq(coll.find({loc: {$geoIntersects: {$geometry: bigPoly20Comp}}}).count(), 2);
assert.commandWorked(coll.createIndex({loc: "2dsphere"}));
assert.eq(coll.find({loc: {$geoWithin: {$geometry: bigPoly20}}}).count(), 3);
assert.eq(coll.find({loc: {$geoIntersects: {$geometry: bigPoly20}}}).count(), 4);
assert.eq(coll.find({loc: {$geoWithin: {$geometry: bigPoly20Comp}}}).count(), 1);
assert.eq(coll.find({loc: {$geoIntersects: {$geometry: bigPoly20Comp}}}).count(), 2);
// Test not indexing and querying big polygon
assert.commandWorked(coll.dropIndexes());
// 1. Without index, insert succeeds, but query ignores big polygon.
var bigPoly10 = {
type: "Polygon",
coordinates: [[[5.0, 5.0], [-5.0, 5.0], [-5.0, -5.0], [5.0, -5.0], [5.0, 5.0]]],
crs: bigCRS
};
assert.commandWorked(coll.insert({_id: "bigPoly10", loc: bigPoly10}));
assert.eq(coll.find({loc: {$geoWithin: {$geometry: bigPoly20}}}).count(), 3);
assert.eq(coll.find({loc: {$geoIntersects: {$geometry: bigPoly20}}}).count(), 4);
assert.eq(coll.find({loc: {$geoWithin: {$geometry: bigPoly20Comp}}}).count(), 1);
assert.eq(coll.find({loc: {$geoIntersects: {$geometry: bigPoly20Comp}}}).count(), 2);
// 2. Building index fails due to big polygon
assert.commandFailed(coll.createIndex({loc: "2dsphere"}));
// 3. After removing big polygon, index builds successfully
assert.commandWorked(coll.remove({_id: "bigPoly10"}));
assert.commandWorked(coll.createIndex({loc: "2dsphere"}));
// 4. With index, insert fails.
assert.writeError(coll.insert({_id: "bigPoly10", loc: bigPoly10}));
// Query geometries that don't support big CRS should error out.
var bigPoint = {type: "Point", coordinates: [0, 0], crs: bigCRS};
var bigLine = {type: "LineString", coordinates: [[-20, 0], [20, 0]], crs: bigCRS};
assert.throws(function() {
coll.find({loc: {$geoIntersects: {$geometry: bigPoint}}}).itcount();
});
assert.throws(function() {
coll.find({loc: {$geoIntersects: {$geometry: bigLine}}}).itcount();
});
|