1
// Tests 2dsphere index option "2dsphereIndexVersion". Verifies that only index version 1 is
4
var coll = db.getCollection("geo_s2indexversion1");
8
// Index build should fail for invalid values of "2dsphereIndexVersion".
11
coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": -1});
15
coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 0});
19
coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2});
23
coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 3});
27
coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": Infinity});
31
coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": "foo"});
35
coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": {a: 1}});
40
// Index build should succeed for valid values of "2dsphereIndexVersion".
43
coll.ensureIndex({geo: "2dsphere"});
44
assert.gleSuccess(db);
47
coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1});
48
assert.gleSuccess(db);
51
coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberInt(1)});
52
assert.gleSuccess(db);
55
coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberLong(1)});
56
assert.gleSuccess(db);
60
// Test compatibility of various GeoJSON objects with 2dsphere.
63
var pointDoc = {geo: {type: "Point", coordinates: [40, 5]}};
64
var lineStringDoc = {geo: {type: "LineString", coordinates: [[40, 5], [41, 6]]}};
65
var polygonDoc = {geo: {type: "Polygon", coordinates: [[[0, 0], [3, 6], [6, 1], [0, 0]]]}};
66
var multiPointDoc = {geo: {type: "MultiPoint",
67
coordinates: [[-73.9580, 40.8003], [-73.9498, 40.7968],
68
[-73.9737, 40.7648], [-73.9814, 40.7681]]}};
69
var multiLineStringDoc = {geo: {type: "MultiLineString",
70
coordinates: [[[-73.96943, 40.78519], [-73.96082, 40.78095]],
71
[[-73.96415, 40.79229], [-73.95544, 40.78854]],
72
[[-73.97162, 40.78205], [-73.96374, 40.77715]],
73
[[-73.97880, 40.77247], [-73.97036, 40.76811]]]}};
74
var multiPolygonDoc = {geo: {type: "MultiPolygon",
75
coordinates: [[[[-73.958, 40.8003], [-73.9498, 40.7968],
76
[-73.9737, 40.7648], [-73.9814, 40.7681],
78
[[[-73.958, 40.8003], [-73.9498, 40.7968],
79
[-73.9737, 40.7648], [-73.958, 40.8003]]]]}};
80
var geometryCollectionDoc = {geo: {type: "GeometryCollection",
81
geometries: [{type: "MultiPoint",
82
coordinates: [[-73.9580, 40.8003],
85
[-73.9814, 40.7681]]},
86
{type: "MultiLineString",
87
coordinates: [[[-73.96943, 40.78519],
88
[-73.96082, 40.78095]],
89
[[-73.96415, 40.79229],
90
[-73.95544, 40.78854]],
91
[[-73.97162, 40.78205],
92
[-73.96374, 40.77715]],
93
[[-73.97880, 40.77247],
94
[-73.97036, 40.76811]]]}]}};
96
// {2dsphereIndexVersion: 1} indexes allow only Point, LineString, and Polygon.
97
coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1});
98
assert.gleSuccess(db);
99
coll.insert(pointDoc);
100
assert.gleSuccess(db);
101
coll.insert(lineStringDoc);
102
assert.gleSuccess(db);
103
coll.insert(polygonDoc);
104
assert.gleSuccess(db);
105
coll.insert(multiPointDoc);
107
coll.insert(multiLineStringDoc);
109
coll.insert(multiPolygonDoc);
111
coll.insert(geometryCollectionDoc);