【问题标题】:geoNear in MongoDB returns empty resultMongoDB 中的 geoNear 返回空结果
【发布时间】:2015-02-20 10:04:36
【问题描述】:

在 MongoDB 中,我创建了一个名为“GIS”的数据库和一个名为“UTILITIES”的集合。我在下面插入了一些 GeoJSON 元素

{ 
"_id" : ObjectId("54e6de457e550c23bc1521a0"), 
"id" : "1", 
"geometry" : {
    "coordinates" : [
        86.74957, 
        21.93157
    ], 
    "type" : "Point", 
    "bbox" : [
        86.74957, 
        21.93157, 
        86.74957, 
        21.93157
    ]
}, 
"properties" : {
    "PLACE" : "Abhoy Medical Store", 
    "LATITUDE" : "21.93157", 
    "LONGITUDE" : "86.74957", 
    "IMG" : "43400012"
}, 
"type" : "Feature", 
"bbox" : [
    86.74957, 
    21.93157, 
    86.74957, 
    21.93157
]
}
{ 
"_id" : ObjectId("54e6de457e550c23bc1521a1"), 
"id" : "2", 
"geometry" : {
    "coordinates" : [
        86.73604, 
        21.92578
    ], 
    "type" : "Point", 
    "bbox" : [
        86.73604, 
        21.92578, 
        86.73604, 
        21.92578
    ]
}, 
"properties" : {
    "PLACE" : "Advanced Homeo Sadan", 
    "LATITUDE" : "21.92578", 
    "LONGITUDE" : "86.73604", 
    "IMG" : "43400123"
}, 
"type" : "Feature", 
"bbox" : [
    86.73604, 
    21.92578, 
    86.73604, 
    21.92578
]
}

然后我创建了一个 2dsphere 索引,如下所示

db.UTILITIES.ensureIndex ({geometry : "2dsphere"})

然后我运行 geoNear 命令如下

db.UTILITIES.runCommand(
{
 geoNear: "UTILITIES",
 near: { type: "Point", coordinates: [ 86.74957, 21.93157 ] },
 spherical: true,
 query: { category: "public" },
 minDistance: 0,
 maxDistance: 7000
}
)

这会返回如下结果

{
"results" : [ ],
"stats" : {
    "nscanned" : 244,
    "objectsLoaded" : 267,
    "avgDistance" : NaN,
    "maxDistance" : 0,
    "time" : 2
},
"ok" : 1
}

返回的结果数组为空。 请提出解决方案。 提前致谢。

【问题讨论】:

    标签: mongodb spatial-index 2dsphere


    【解决方案1】:

    尝试更改o评论这部分:

    query: { category: "public" }

    因为元素中没有“类别”字段

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-19
      • 2021-07-22
      • 2020-10-21
      • 1970-01-01
      • 1970-01-01
      • 2021-10-16
      • 1970-01-01
      相关资源
      最近更新 更多