MongoDB:在多边形上使用$ geoIntersect“格式错误的地理查询”

时间:2013-09-17 05:09:49

标签: mongodb geojson

我在集合中有事件,每个事件都包含一个所需的位置,设置GeoJSON多边形。

我在另一个系列中也有服务提供商,也有GeoJSON Polygon,表明他们可以提供的区域。

对于给定的服务提供商,我正在尝试列出兼容区域中的所有事件。

然而,我收到此错误:

 Malformed geo query: { $geoIntersects: { $geometry: { type: "Polygon", coordinates: [ [ [ -31.59327575763251, 115.8574693000001 ], [ -31.59676306691357, 115.9162469300458 ], [ -31.60715789289806, 115.9738935747774 ], ...

我的多边形是关闭的(第一个和最后一个坐标是相同的),所以它不是来自那里。

以下是事件:

活动:

[
    {
        "_id": "5237d4bd9899e67c0e000004",
        "area": "area",
        "authtoken": "e3bf38ff9a1f132a7cc86ea045cf3951",
        "budget": 1800,
        "creation_date": {
            "sec": 1379390653,
            "usec": 0
        },
        "description": "Banana banana banana banana banana banana banana banana bananaaaaaaaaaaaaaaaaa!!!",
        "ends": {
            "sec": 1383343200,
            "usec": 0
        },
        "geo": {
            "type": "Polygon",
            "coordinates": [
                [
                    [
                        -33.740154878816,
                        150.9241267
                    ],
                    [
                        -33.741901642057,
                        150.95422987078
                    ],
                    [
                        -33.747108144055,
                        150.98375074498
                    ],
                    [
                        -33.755673663135,
                        151.01211808166
                    ],
                    [
                        -33.767432456928,
                        151.03878255704
                    ],
                    [
                        -33.782156913661,
                        151.0632272399
                    ],
                    [
                        -33.799561885809,
                        151.08497749366
                    ],
                    [
                        -33.819310129033,
                        151.10361012448
                    ],
                    [
                        -33.841018749004,
                        151.11876160464
                    ],
                    [
                        -33.819310129033,
                        150.74464327552
                    ],
                    [
                        -33.799561885809,
                        150.76327590634
                    ],
                    [
                        -33.782156913661,
                        150.7850261601
                    ],
                    [
                        -33.767432456928,
                        150.80947084296
                    ],
                    [
                        -33.755673663135,
                        150.83613531834
                    ],
                    [
                        -33.747108144055,
                        150.86450265502
                    ],
                    [
                        -33.741901642057,
                        150.89402352922
                    ],
                    [
                        -33.740154878816,
                        150.9241267
                    ]
                ]
            ]
        },
        "guests": 180,
        "loc": {
            "city": "Liverpool",
            "state": "NSW",
            "country": "AU",
            "lat": -33.9200192,
            "lng": 150.9241267,
            "timezone": "Australia\/Sydney"
        },
        "name": "Bananaaaaaaaa!",
        "services": [
            {
                "creation_date": {
                    "sec": 1379390661,
                    "usec": 0
                },
                "data": {
                    "name": "Bananaaaaaaaaaaa!!!!!",
                    "request": "Banana!",
                    "description": " banana banana banana banana banana banana banana banana banana",
                    "budget": "1400"
                },
                "event": "aaca6751-75b2-4cd9-a76a-99d4ee56fb6a",
                "service": "a9fe4bd0-d4f2-4f2c-8b81-4899ac19c44f",
                "uid": "0d92f274-67a3-4d2f-b1c8-d771fd84c113",
                "uuid": "15ceedd5-608b-48e4-8a05-b60ee4c4c5bb",
                "type": "Food & Drinks"
            }
        ],
        "starts": {
            "sec": 1383300000,
            "usec": 0
        },
        "type": {
            "_id": "521666701e6accf7afc1a0e3",
            "icon": "uploads\/event-types\/icon-3891a6f4-760f-43f2-ab3a-a51c61fd8d0d.png?rnd=0.6323562911552134",
            "name": "Meeting",
            "uuid": "3891a6f4-760f-43f2-ab3a-a51c61fd8d0d"
        },
        "uid": "0d92f274-67a3-4d2f-b1c8-d771fd84c113",
        "uuid": "aaca6751-75b2-4cd9-a76a-99d4ee56fb6a",
        "within": {
            "km": 20,
            "addr": "liverpool, nsw"
        }
    },
    {
        "_id": "5237d50a9899e67c0e000005",
        "area": "area",
        "authtoken": "e3bf38ff9a1f132a7cc86ea045cf3951",
        "budget": 1800,
        "creation_date": {
            "sec": 1379390730,
            "usec": 0
        },
        "description": "Boo!!!",
        "ends": {
            "sec": 1383285600,
            "usec": 0
        },
        "geo": {
            "type": "Polygon",
            "coordinates": [
                [
                    [
                        -32.086853059112,
                        116.0081156
                    ],
                    [
                        -32.088163946126,
                        116.03027505189
                    ],
                    [
                        -32.092071203806,
                        116.05200507521
                    ],
                    [
                        -32.098499107954,
                        116.07288445521
                    ],
                    [
                        -32.1073230624,
                        116.09250825588
                    ],
                    [
                        -32.118371984525,
                        116.11049558927
                    ],
                    [
                        -32.131431584032,
                        116.12649694645
                    ],
                    [
                        -32.146248475035,
                        116.14020095399
                    ],
                    [
                        -32.330851613336,
                        116.10195418015
                    ],
                    [
                        -32.289125251893,
                        115.86992020233
                    ],
                    [
                        -32.2721989398,
                        115.86018847275
                    ],
                    [
                        -32.254291845681,
                        115.85334073219
                    ],
                    [
                        -32.235752983166,
                        115.84950870874
                    ],
                    [
                        -32.098499107954,
                        115.94334674479
                    ],
                    [
                        -32.092071203806,
                        115.96422612479
                    ],
                    [
                        -32.088163946126,
                        115.98595614811
                    ],
                    [
                        -32.086853059112,
                        116.0081156
                    ]
                ]
            ]
        },
        "guests": 700,
        "loc": {
            "city": "Byford",
            "state": "WA",
            "country": "AU",
            "zipcode": "6122",
            "lat": -32.2217513,
            "lng": 116.0081156,
            "timezone": "Australia\/Perth"
        },
        "name": "Halloween",
        "services": [
            {
                "creation_date": {
                    "sec": 1379390749,
                    "usec": 0
                },
                "data": {
                    "name": "Badass lighting",
                    "description": "Boom! I want that!",
                    "type": [
                        "Furniture",
                        "Lighting\/lasers",
                        "LED screens",
                        "Dancefloor"
                    ],
                    "budget": "800"
                },
                "event": "a6c28e98-b647-4224-8bff-f0b7e5c453c3",
                "service": "4d4f370e-5780-4794-b988-df9d7a9ed644",
                "uid": "0d92f274-67a3-4d2f-b1c8-d771fd84c113",
                "uuid": "217c4896-a986-4c0a-a6c7-46c9aa74cf27",
                "type": "Equipment Hire"
            }
        ],
        "starts": {
            "sec": 1383256800,
            "usec": 0
        },
        "type": {
            "_id": "521666701e6accf7afc1a0e3",
            "icon": "uploads\/event-types\/icon-3891a6f4-760f-43f2-ab3a-a51c61fd8d0d.png?rnd=0.6323562911552134",
            "name": "Meeting",
            "uuid": "3891a6f4-760f-43f2-ab3a-a51c61fd8d0d"
        },
        "uid": "0d92f274-67a3-4d2f-b1c8-d771fd84c113",
        "uuid": "a6c28e98-b647-4224-8bff-f0b7e5c453c3",
        "within": {
            "km": 15,
            "addr": "byford"
        }
    }
]

这是我的查询对象:

db.events.find({
    "geo": {
        "$geoIntersects": {
            "$geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            -31.593275757633,
                            115.8574693
                        ],
                        [
                            -31.596763066914,
                            115.91624693005
                        ],
                        [
                            -32.087153956437,
                            116.25114123685
                        ],
                        [
                            -32.13233852915,
                            116.22535569049
                        ],
                        [
                            -32.174036124673,
                            116.19236795072
                        ],
                        [
                            -32.304841443191,
                            115.76898154226
                        ],
                        [
                            -32.290955790481,
                            115.7119268346
                        ],
                        [
                            -31.841206471153,
                            115.45474133646
                        ],
                        [
                            -31.794742552646,
                            115.4770638401
                        ],
                        [
                            -31.751364552714,
                            115.50675244396
                        ],
                        [
                            -31.711911850434,
                            115.5432228167
                        ],
                        [
                            -31.677146863424,
                            115.58576206658
                        ],
                        [
                            -31.607157892898,
                            115.74104502522
                        ],
                        [
                            -31.596763066914,
                            115.79869166995
                        ],
                        [
                            -31.593275757633,
                            115.8574693
                        ]
                    ]
                ]
            }
        }
    }
})

我错过了什么? 我的查询似乎与地理查询的官方mongodb doc相同。

提前致谢!

1 个答案:

答案 0 :(得分:1)

您的坐标指定为[纬度,经度]。 MongoDB要求您为2dsphere几何体以相反的顺序指定坐标:[经度,纬度]。

我交换了坐标顺序后,您的查询对我有效。