首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mongodb geosphere和haystack索引拒绝有效的行字符串

Mongodb geosphere和haystack索引拒绝有效的行字符串
EN

Stack Overflow用户
提问于 2015-01-26 09:21:00
回答 1查看 104关注 0票数 2

我尝试将以下geojsonlint数据分别插入到三个地理索引中。唯一接受数据的是2d索引。

haystack索引产生以下错误:

代码语言:javascript
复制
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产生以下错误:

代码语言:javascript
复制
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
}

有谁有什么想法吗?

代码语言:javascript
复制
{
    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
    }
}
EN

回答 1

Stack Overflow用户

发布于 2015-01-26 11:42:30

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

示例代码:

代码语言:javascript
复制
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.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28143569

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档