c++ - Mongodb geosphere 和 haystack 索引拒绝有效的行字符串

标签 c++ mongodb geojson

我试图将以下 geojsonlint 数据插入三个地理索引中的每一个。唯一接受数据的是二维索引。

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
    }
}

最佳答案

您的索引在错误的字段上。 索引字段应该是 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.

关于c++ - Mongodb geosphere 和 haystack 索引拒绝有效的行字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28143569/

相关文章:

C++ - 将 .at() 方法与字符串一起使用时出现问题

java - 如何在不使用模式匹配的情况下使用 java api 查询 “like” 的 mongodb?

javascript - 如何从 HTML 表单调用现有的 REST api?

mongodb - 作为服务运行时将 MongoDB 绑定(bind)到 IP 地址

javascript - GeoJson amchart maps geoJson 有什么问题?

c++ - noexcept 说明符内的参数包

C++ 错误 : invalid conversion from ‘char’ to ‘const char*’ [-fpermissive]

java - 从 java/Android Studio 中的 geojson 特征集合中提取坐标 lat lng

c++ - 服务器在 16000 个请求后挂起一段时间

c# - 如何将 GeoJSON 数据绑定(bind)到 ASP.NET Core 中的参数?