MongoDB $ geoWithin不工作

时间:2014-11-05 07:52:59

标签: mongodb geospatial

我在mongodb中有一个集合,我正在运行GeoWithin进行循环查询以过滤数据,但它表现得很奇怪。

收集文件

{
    "_id" : NumberLong(3),
    "lastUpdated" : ISODate("2014-11-05T06:14:49.497Z"),
    "lastUpdatedBy" : NumberLong(4),
    "name" : "test",
    "user" : NumberLong(4),
    "visibility" : true,
    "visibleTo" : "EveryOne",
    "visiblityCity" : [
        {
            "country" : "United States",
            "countryCode" : "US",
            "location" : {
                "lat" : 40.7127837,
                "long" : -74.00594130000002
            },
            "name" : "New York",
            "state" : "New York"
        }
    ],
    "visiblityCountry" : [
        {
            "countryCode" : "US",
            "location" : {
                "lat" : 40.7127837,
                "long" : -74.00594130000002
            },
            "name" : "United States"
        }
    ]
}

我在visiblityCity.location

上创建了2d索引
db.<collection name>.ensureIndex( {"visiblityCity.location" : "2d" })

db..getIndexes();结果如下

[
    {
        "v" : 1,
        "key" : {
            "_id" : 1
        },
        "ns" : "mopi.survey",
        "name" : "_id_"
    },
    {
        "v" : 1,
        "key" : {
            "visiblityCity.location" : "2d"
        },
        "ns" : "mopi.survey",
        "name" : "visiblityCity.location_2d"
    },
    {
        "v" : 1,
        "key" : {
            "visiblityCity.location" : "2dsphere"
        },
        "ns" : "mopi.survey",
        "name" : "visiblityCity.location_2dsphere"
    }
]

现在我正在运行命令

  

db.survey.find({“visiblityCity.location”:{“$ geoWithin”:{“$ center”:[[84.7274,25.7848],0.14]}}})。count();       0

当我跑步时

  

db.survey.find({“visiblityCity.location”:{“$ geoWithin”:{“$ center”:[[84.7274,25.7848],85]}}})。count();   2

因为85和0.14是弧度值。我必须得到一个Radian值为0.14的结果,但我得到0个结果。

我得到的弧度85的结果计数为2,两个文件的距离分别为85km和1349km。当我以弧度转换距离时,我得到的弧度值远小于85.

0 个答案:

没有答案