4
pointA = { "type" : "Point", "coordinates": [ 40, 5 ] }
5
t.insert( {geo : pointA , nonGeo: "pointA"})
7
pointD = { "type" : "Point", "coordinates": [ 41.001, 6.001 ] }
8
t.insert( {geo : pointD , nonGeo: "pointD"})
10
someline = { "type" : "LineString", "coordinates": [ [ 40, 5], [41, 6]]}
11
t.insert( {geo : someline , nonGeo: "someline"})
13
pointB = { "type" : "Point", "coordinates": [ 41, 6 ] }
14
t.insert( {geo : pointB , nonGeo: "pointB"})
16
pointC = { "type" : "Point", "coordinates": [ 41, 6 ] }
17
t.insert( {geo : pointC} )
19
// Add a point within the polygon but not on the border. Don't want to be on
20
// the path of the polyline.
21
pointE = { "type" : "Point", "coordinates": [ 40.6, 5.4 ] }
22
t.insert( {geo : pointE} )
24
// Make sure we can index this without error.
25
t.insert({nonGeo: "noGeoField!"})
27
somepoly = { "type" : "Polygon",
28
"coordinates" : [ [ [40,5], [40,6], [41,6], [41,5], [40,5]]]}
29
t.insert( {geo : somepoly, nonGeo: "somepoly" })
31
t.ensureIndex( { geo : "2dsphere", nonGeo: 1 } )
32
// We have a point without any geo data. Don't error.
33
assert(!db.getLastError())
35
res = t.find({ "geo" : { "$geoIntersects" : { "$geometry" : pointA} } });
36
assert.eq(res.count(), 3);
38
res = t.find({ "geo" : { "$geoIntersects" : { "$geometry" : pointB} } });
39
assert.eq(res.count(), 4);
41
res = t.find({ "geo" : { "$geoIntersects" : { "$geometry" : pointD} } });
42
assert.eq(res.count(), 1);
44
res = t.find({ "geo" : { "$geoIntersects" : { "$geometry" : someline} } })
45
assert.eq(res.count(), 5);
47
res = t.find({ "geo" : { "$geoIntersects" : { "$geometry" : somepoly} } })
48
assert.eq(res.count(), 6);
50
res = t.find({ "geo" : { "$within" : { "$geometry" : somepoly} } })
51
assert.eq(res.count(), 6);
53
res = t.find({ "geo" : { "$geoIntersects" : { "$geometry" : somepoly} } }).limit(1)
54
assert.eq(res.itcount(), 1);
56
res = t.find({ "nonGeo": "pointA",
57
"geo" : { "$geoIntersects" : { "$geometry" : somepoly} } })
58
assert.eq(res.count(), 1);
60
// Don't crash mongod if we give it bad input.
62
t.ensureIndex({loc: "2dsphere", x:1})
64
assert.throws(function() { return t.count({loc: {$foo:[0,0]}}) })
65
assert.throws(function() { return t.find({ "nonGeo": "pointA",
66
"geo" : { "$geoIntersects" : { "$geometry" : somepoly},
67
"$near": {"$geometry" : somepoly }}}).count()})
69
// If we specify a datum, it has to be valid (WGS84).
71
t.ensureIndex({loc: "2dsphere"})
72
t.insert({loc: {type:'Point', coordinates: [40, 5], crs:{ type: 'name', properties:{name:'EPSG:2000'}}}})
73
assert(db.getLastError());
74
assert.eq(0, t.find().itcount())
75
t.insert({loc: {type:'Point', coordinates: [40, 5]}})
76
assert(!db.getLastError());
77
t.insert({loc: {type:'Point', coordinates: [40, 5], crs:{ type: 'name', properties:{name:'EPSG:4326'}}}})
78
assert(!db.getLastError());
79
t.insert({loc: {type:'Point', coordinates: [40, 5], crs:{ type: 'name', properties:{name:'urn:ogc:def:crs:OGC:1.3:CRS84'}}}})
80
assert(!db.getLastError());
82
// We can pass level parameters and we verify that they're valid.
83
// 0 <= coarsestIndexedLevel <= finestIndexedLevel <= 30.
86
t.ensureIndex({loc: "2dsphere"}, {finestIndexedLevel: 17, coarsestIndexedLevel: 5})
87
assert(!db.getLastError());
91
t.ensureIndex({loc: "2dsphere"}, {finestIndexedLevel: 31, coarsestIndexedLevel: 5})
92
assert(db.getLastError());
96
t.ensureIndex({loc: "2dsphere"}, {finestIndexedLevel: 30, coarsestIndexedLevel: 0})
97
assert(!db.getLastError());
101
t.ensureIndex({loc: "2dsphere"}, {finestIndexedLevel: 30, coarsestIndexedLevel: -1})
102
assert(db.getLastError());