2dsphere インデックス コレクションに Point を挿入し、Polygon 内で見つけようとしています。
c = db.foo;
c.ensureIndex({'value.geometry': '2dsphere'});
c.insert({value: {geometry: {type: "Point", coordinates: [0, 0]}}});
c.findOne({'value.geometry': {$geoWithin: {$geometry:
{"type":"Polygon","coordinates":[[[-90,-90],[90,-90],[90,90],[-90,90],[-90,-90]]]}}}})
// Point is found
ただし、幅が 180° を超えるポリゴンで同じことを行うと、ポイントが見つかりません。
c = db.foo;
c.ensureIndex({'value.geometry': '2dsphere'});
c.insert({value: {geometry: {type: "Point", coordinates: [0, 0]}}});
c.findOne({'value.geometry': {$geoWithin: {$geometry:
{"type":"Polygon","coordinates":[[[-90.1,-90],[90.1,-90],[90.1,90],[-90.1,90],[-90.1,-90]]]}}}})
// no result -- why?
MongoDB のマニュアルには、これに関する情報が見つかりませんでした。なんで限界?