使用MongoDB 3.2我试图在Points集合上使用2dsphere查询.
假设我在the_geom字段上有一个带有2dsphere索引的à集合cust_5_abcd.
在集合中添加几何:
db.cust_5_abcd.insert({
"chps0" : "Texte d'une ligne",
"the_geom" : {
"type" : "Point",
"coordinates" : [
1.032715,
40.380028
]
}})
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试使用$ geoWithin查询此Point以获取特定Polygon中的所有数据.如果我使用带有GeoJSON定义的$ geometry,或者使用$ polygon和严格坐标,那么我就会得到不同的结果.也许文档中的某些内容缺失或者我误解了.
使用$ geometry会导致无结果:
db.cust_5_abcd.find( { the_geom:
{ $geoWithin:
{ $geometry:
{
"type": "Polygon",
"coordinates": [
[
[ -16.237793, 40.162083 ],
[ -16.237793, 51.835778 ],
[ -13.776855, 51.835778 ],
[ -13.776855, 41.426253 ],
[ 14.765625, 41.426253 ],
[ 14.765625, 40.162083 ],
[ -16.237793, 40.162083 ] …Run Code Online (Sandbox Code Playgroud) mongodb ×1