Mongodb geosphere和haystack索引拒绝有效的线串

时间:2015-01-26 01:21:00

标签: c++ mongodb geojson

我尝试使用三个地理索引中的每一个插入以下geojsonlint数据。唯一接受数据的是2d索引。

haystack索引会产生以下错误:

insertDocument :: caused by :: 16776 geo field is not a number
{
    "v" : 1,
    "key" : {
        "geometry.coordinates" : "geoHaystack",
        "properties.asset_type" : 1
    },
    "name" : "geometry.coordinates_geoHaystack_properties.asset_type_1",
    "ns" : "smallcell.poles",
    "bucketSize" : 1
}

2dsphere产生以下错误:

insertDocument :: caused by :: 16755 Can't extract geo keys from object, malformed geometry?

{
    "v" : 1,
    "key" : {
        "geometry.coordinates" : "2dsphere"
    },
    "name" : "geometry.coordinates_2dsphere",
    "ns" : "smallcell.poles",
    "2dsphereIndexVersion" : 2
}

有没有人有任何想法?

{
    type : "Feature",
    geometry : {
        type : "LineString",
        coordinates : [[-118.6058, 34.17195], [-118.60589, 34.17195], [-118.606057, 34.171953], [-118.606096, 34.171954], [-118.60647, 34.17196], [-118.60702, 34.17196], [-118.60713, 34.17196], [-118.6076, 34.17195], [-118.6077, 34.17195], [-118.60779, 34.171949], [-118.6088, 34.17194], [-118.609203, 34.17194], [-118.60932, 34.17194], [-118.60964, 34.17195], [-118.6102, 34.17198], [-118.6104, 34.172], [-118.610704, 34.172031], [-118.61089, 34.17205], [-118.61115, 34.17207], [-118.61135, 34.17207], [-118.61175, 34.17204], [-118.61215, 34.17199], [-118.61265, 34.17196], [-118.61366, 34.17196], [-118.61455, 34.17196], [-118.61678, 34.17196], [-118.61819, 34.17197], [-118.61896, 34.17196], [-118.61971, 34.17195], [-118.620452, 34.17195], [-118.62115, 34.17195], [-118.62153, 34.17195], [-118.62287, 34.17196], [-118.62333, 34.17197], [-118.6238, 34.17197], [-118.62543, 34.17196], [-118.62731, 34.17194], [-118.628244, 34.17194], [-118.62957, 34.17194], [-118.63206, 34.17192]]
    },
    properties : {
        id : 0.0,
        asset_type : "FBR",
        carrier : "AT&T",
        type : "ON_ROAD",
        cbsa : "31100",
        lata : "730",
        zip : null,
        state : null
    }
}

1 个答案:

答案 0 :(得分:0)

您的索引位于错误的字段上。 索引字段应为geometry,而不是geometry.coordinates

示例代码:

var lineString = {
    type : "Feature",
    geometry : {
        type : "LineString",
        coordinates : [[-118.6058, 34.17195], [-118.60589, 34.17195], [-118.606057, 34.171953], [-118.606096, 34.171954], [-118.60647, 34.17196], [-118.60702, 34.17196], [-118.60713, 34.17196], [-118.6076, 34.17195], [-118.6077, 34.17195], [-118.60779, 34.171949], [-118.6088, 34.17194], [-118.609203, 34.17194], [-118.60932, 34.17194], [-118.60964, 34.17195], [-118.6102, 34.17198], [-118.6104, 34.172], [-118.610704, 34.172031], [-118.61089, 34.17205], [-118.61115, 34.17207], [-118.61135, 34.17207], [-118.61175, 34.17204], [-118.61215, 34.17199], [-118.61265, 34.17196], [-118.61366, 34.17196], [-118.61455, 34.17196], [-118.61678, 34.17196], [-118.61819, 34.17197], [-118.61896, 34.17196], [-118.61971, 34.17195], [-118.620452, 34.17195], [-118.62115, 34.17195], [-118.62153, 34.17195], [-118.62287, 34.17196], [-118.62333, 34.17197], [-118.6238, 34.17197], [-118.62543, 34.17196], [-118.62731, 34.17194], [-118.628244, 34.17194], [-118.62957, 34.17194], [-118.63206, 34.17192]]
    },
    properties : {
        id : 0.0,
        asset_type : "FBR",
        carrier : "AT&T",
        type : "ON_ROAD",
        cbsa : "31100",
        lata : "730",
        zip : null,
        state : null
    }
};
db.testLS.remove({});
db.testLS.ensureIndex( { geometry : "2dsphere" } );
db.testLS.insert( lineString );

// example query using a point
db.testLS.find( { geometry : {
    $near : {
        $geometry : {
            type : "Point",
            coordinates : [ 110, 30 ]
        }
    }
} } );
// returns the lineString object.