File: geo_s2indexoldformat.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (28 lines) | stat: -rwxr-xr-x 1,005 bytes parent folder | download | duplicates (3)
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
// Make sure that the 2dsphere index can deal with non-GeoJSON points.
// 2dsphere does not accept legacy shapes, only legacy points.
t = db.geo_s2indexoldformat
t.drop()

t.insert( {geo : [40, 5], nonGeo: ["pointA"]})
t.insert( {geo : [41.001, 6.001], nonGeo: ["pointD"]})
t.insert( {geo : [41, 6], nonGeo: ["pointB"]})
t.insert( {geo : [41, 6]} )
t.insert( {geo : {x:40.6, y:5.4}} )

t.ensureIndex( { geo : "2dsphere", nonGeo: 1 } )

res = t.find({ "geo" : { "$geoIntersects" : { "$geometry": {x:40, y:5}}}})
assert.eq(res.count(), 1);

res = t.find({ "geo" : { "$geoIntersects" : {"$geometry": [41,6]}}})
assert.eq(res.count(), 2);

// We don't support legacy polygons in 2dsphere.
t.insert( {geo : [[40,5],[40,6],[41,6],[41,5]], nonGeo: ["somepoly"] })
assert(db.getLastError());

t.insert( {geo : {a:{x:40,y:5},b:{x:40,y:6},c:{x:41,y:6},d:{x:41,y:5}}})
assert(db.getLastError());

res = t.find({ "geo" : { "$geoIntersects" : {"$geometry": [[40,5],[40,6],[41,6],[41,5]]}}})
assert(db.getLastError());