2

コレクションにイベントがあり、それぞれに目的の場所が含まれており、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 と同じようです。

前もって感謝します!

4

1 に答える 1

1

座標は [緯度、経度] として指定されます。MongoDB では、2dsphere ジオメトリとは逆の順序で座標を指定する必要があります: [経度、緯度]。

座標の順序を入れ替えると、クエリが機能しました。

于 2013-09-17T15:39:18.327 に答える