0

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
}

返された結果配列は空です。親切に解決策を提案してください。前もって感謝します。

4

1 に答える 1

0

この部分を変更してみてください:

query: { category: "public" }

要素には「カテゴリ」フィールドがないため

于 2015-03-12T17:44:25.730 に答える