使用Polygons和Mongoose的地理空间查询有什么问题?

时间:2011-10-12 16:54:55

标签: mongodb geospatial mongoose

我正在使用$polygon搜索进行地理空间查询。我的疑问是:

{
    'location_latLong': {
        '$within': {
            '$polygon': {
                point1: {
                    lon: '-74.2621',
                    lat: '40.5788'
                },
                point2: {
                    lon: '-74.2621',
                    lat: '40.8494'
                },
                point3: {
                    lon: '-73.7499',
                    lat: '40.8494'
                },
                point4: {
                    lon: '-73.7499',
                    lat: '40.5788'
                }
            }
        }
    }
}

在我的收藏中,我有一个CLEARLY位于多边形内的文档:

{
    "_id": ObjectId("4e95c285cb8a0efc2b00001a"),
    "addedOn": Date(1318437509839),
    "checkinDate": Date(1318392000000),
    "checkinTime": Date(1318437476000),
    "location_city": "New York",
    "location_country": "United States",
    "location_latLong": {
        "xLon": -74.007124,
        "yLat": 40.71455
    },
    "location_source": "personprofile",
    "location_state": "New York",
    "location_zip": ""
}

我在2d上有一个location_latLong索引。我知道MongoDB忽略了关键名称(据说),所以这无关紧要。那么为什么这会返回0结果?

修改 我刚刚按照评论中的建议运行了explain,我得到了:

{
    "cursor" : "GeoBrowse-polygon",
    "nscanned" : 0,
    "nscannedObjects" : 0,
    "n" : 0,
    "millis" : 0,
    "nYields" : 0,
    "nChunkSkips" : 0,
    "isMultiKey" : false,
    "indexOnly" : false,
    "indexBounds" : {
        "location_latLong" : [
            [
                [
                    0,
                    0
                ],
                [
                    0.000021457672119140625,
                    0.000021457672119140625
                ]
            ],
            [
                [
                    -0.000021457672119140625,
                    -0.000021457672119140625
                ],
                [
                    0,
                    0
                ]
            ],
            [
                [
                    -0.000021457672119140625,
                    0
                ],
                [
                    0,
                    0.000021457672119140625
                ]
            ],
            [
                [
                    0,
                    -0.000021457672119140625
                ],
                [
                    0.000021457672119140625,
                    0
                ]
            ]
        ]
    },
    "keysChecked" : NumberLong(8),
    "lookedAt" : NumberLong(4),
    "matchesPerfd" : NumberLong(0),
    "objectsLoaded" : NumberLong(0),
    "pointsLoaded" : NumberLong(0)
}

1 个答案:

答案 0 :(得分:1)

我解决了这个问题。我正在通过弦乐队,而且我应该通过花车。

感谢您的时间=)