没有从$ geoNear聚合获得结果

时间:2015-03-14 21:10:02

标签: mongodb

你能帮我弄清楚为什么这个查询没有返回结果吗?

我使用ogr2​​ogr导入形状文件将其转换为geoJson,然后使用以下命令将其导入Mongo:     " mongoimport --db ht - 收集设施< f.json" 然后,我创建了这样的索引:" db.facilities.ensureIndex({" geometry":" 2dsphere"})"

这是一个示例文档,以及不返回任何内容和索引的查询:

    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
    ]
}

}

这是索引。我尝试了几何"几何"和#34; geometry.coordinates"结果相同:

    {
"geometry.coordinates" : "2dsphere"

}

1 个答案:

答案 0 :(得分:1)

执行geoNear时,除了位置过滤器外,还会应用查询过滤器。如果满足$ geoNear的文档都不属于" public"那么您的查询过滤器为{ type: "public" }。然后你就不会得到任何文件了。

相关问题