【问题标题】:Get all items withing a bounding box in MongoDB获取MongoDB中边界框内的所有项目
【发布时间】:2013-11-13 00:23:38
【问题描述】:

我在查询匹配 BoundingBox 内的项目时遇到问题。 我已经在 mongo documentation 中阅读了很多关于 $box$geoWithin 的内容但没有成功,但无法弄清楚为什么查询框中的项目没有得到结果。

这里是一个示例,来自定义的架构,其中包含一个项目和查询以将其取出

架构定义看起来像这样,它的验证正在工作。

/**
 * Media location values (Point, LineString, Polygon)
 * @property location
 * @type {Object}
 */
 location:{
            "type":Object,
            "index":"2dsphere"
 },

里面的一个项目看起来像这样(这是查询的结果):

{
    "_account": "52796da308d618090b000001",
    "_id": "5280d9c6592dce2d36000001",
    "location": {
        "coordinates": [
            50.109230555555555,
            8.757613888888889
        ],
        "type": "Point"
    },
    "name": "Büro",
    "preview": "/img/thumbs/13869-2gqv8n.JPG",
    "type": "image/jpeg",
    "added": "2013-11-11T13:21:10.951Z",
    "latlng": [ ],
    "shares": [ ],
    "shared": false,
    "tags": [ ]
}

获取项目的查询看起来像

{
    // tried also "location.coordinates" without luck
    "location": {
        " $geoWithin": {
            "$box": [
                [
                    49.99825021043669,
                    8.543586730957031
                ],
                [
                    50.139285461134996,
                    8.996772766113281
                ]
            ]
        }
    }
}

结果总是空数组有什么问题?

【问题讨论】:

    标签: javascript mongodb mongoose geojson


    【解决方案1】:

    我可以看到这里有一个问题。 " $geoWithin" 不应该是"$geoWithin" 吗??

    【讨论】:

    • 你知道在结果中还需要什么线串和多边形吗?
    猜你喜欢
    • 1970-01-01
    • 2011-07-10
    • 2022-08-21
    • 1970-01-01
    • 2011-09-01
    • 1970-01-01
    • 2021-02-01
    • 2023-02-01
    • 1970-01-01
    相关资源
    最近更新 更多