【发布时间】:2016-10-07 04:54:17
【问题描述】:
使用 MongoDB 3.2 我正在尝试对点集合使用 2dsphere 查询。
假设我有一个集合 cust_5_abcd,在 the_geom 字段上有一个 2dsphere 索引。
在集合中添加几何体:
db.cust_5_abcd.insert({
"chps0" : "Texte d'une ligne",
"the_geom" : {
"type" : "Point",
"coordinates" : [
1.032715,
40.380028
]
}})
现在我正在尝试使用 $geoWithin 查询此点,以获取特定多边形内的所有数据。如果我将 $geometry 与 GeoJSON 定义一起使用,或者与 $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 ]
]
]
}
}
}
})
使用 $polygon 返回我的点:
db.cust_5_abcd.find( { the_geom:
{ $geoWithin:
{ $polygon:
[
[ -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 ]
]
}
}
})
【问题讨论】:
-
这有点奇怪...,尤其是 query.explain("executionStats") 表明第一个查询正在使用索引(如果已创建)而另一个没有...
标签: mongodb