收集架构:
42
收集索引:
{
"_id" : ObjectId("59629006d5idf90ed8013932"),
"AssetNo" : "1",
"location" : {
"type" : "Point",
"coordinates" : [
-79.33801,
35.31775
]
}
查询:
>db.temp.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "NearestNeighbor.temp"
},
{
"v" : 1,
"key" : {
"location" : "2dsphere"
},
"name" : "location_2dsphere",
"ns" : "NearestNeighbor.temp",
"2dsphereIndexVersion" : 2
}
]
此查询返回零文档。两个坐标点之间的距离约为0.21英里。 (我希望找到半径为0.3英里的点,上面的文档理想地应位于球体/圆圈内)
这是我所提到的查询格式:
db.temp.find({ "location" : { "$geoWithin" : { "$centerSphere" : [ [ -79.33519333 , 35.324] , 0.3 / 3963.2]}}})
将半径增加到0.5英里:
db.<name>.find({
loc: { $geoWithin:
{
$centerSphere: [ [ long, lat ],
radius in MILES/3963.2 ] }
}
})
该文件出现:
db.temp.find({ "location" : { "$geoWithin" : { "$centerSphere" : [ [ -79.33519333 , 35.324] , 0.5/3963.2]}}})
我尝试过调试但找不到问题。有什么建议吗?