【问题标题】:Not getting results from $geoNear aggregate没有从 $geoNear 聚合中获得结果
【发布时间】: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


【解决方案1】:

执行geoNear 时,除了位置过滤器外,还会应用查询过滤器。您的查询过滤器是{ type: "public" },如果满足 $geoNear 的文档都不是“public”类型,那么您将不会得到任何文档。

【讨论】:

    猜你喜欢
    • 2015-04-25
    • 2021-05-12
    • 1970-01-01
    • 2013-04-29
    • 2023-02-10
    • 2020-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多