【发布时间】:2015-03-14 21:10:01
【问题描述】:
你能帮我弄清楚为什么这个查询没有返回结果吗?
我使用 ogr2ogr 导入了一个 shape 文件以将其转换为 geoJson,然后使用以下命令将其导入 Mongo: “mongoimport --db ht--收集设施
这是一个示例文档,以及不返回任何内容的查询和索引:
db.epa_facilities.aggregate([
{
$geoNear: {
near: { type: "Point", coordinates: [ -74.501340, 39.944520 ] },
distanceField: "dist.calculated",
maxDistance: 3,
query: { type: "public" },
includeLocs: "dist.location",
spherical: true,
distanceMultiplier: 3959
}
}
])
这是文档(为简洁起见,属性已删除):
{
"_id" : ObjectId("54ff20a90e46de508d1dae93"),
"type" : "Feature",
"properties" : {
… },
"geometry" : {
"type" : "Point",
"coordinates" : [
-74.50134,
39.9445200009289
]
}
}
这是索引。我尝试了“几何”和“geometry.coordinates”,结果相同:
{
"geometry.coordinates" : "2dsphere"
}
【问题讨论】:
-
你有一个可选的查询过滤器 { type:"public"} - 你真的有与之匹配的文档吗?当我插入您的示例文档并运行将“public”更改为“Feature”的聚合时,我可以很好地取回文档。
-
我会把它作为答案然后:)
标签: mongodb