猫鼬查询不返回GeoJSON的geometry属性

时间:2018-12-02 11:02:53

标签: node.js mongoose leaflet gis geojson

给出我数据库中的以下文档:

{
    "_id" : ObjectId("5c03b36d13032cc192d33f84"),
    "type" : "Feature",
    "properties" : {
        "name" : "point 1",
        "amenity" : "test",
        "popupContent" : "test"
    },
    "geometry" : {
        "type" : "Point",
        "coordinates" : [ 
           [ -3.68814468383789, 
            40.5248912033234]
        ]
    }
}

并给出以下猫鼬查询:

function findVertex(req,res){
    Vertex2.find({"_id":"5c03b36d13032cc192d33f84"}, function(err,obj) {
        if(err){
            res.status(500).send(error);
        }else{
            var geoJson=obj[0];

            console.log(geoJson)
            res.status(200).send(geoJson);
        }

    })
}

我收到的是:

{ properties: { name: 'point 1', amenity: 'test', popupContent: 'test' },
  _id: 5c03b36d13032cc192d33f84,
  type: 'Feature' }

为什么几何不在响应中?如果我在robomongo中执行相同的查询,则会得到带有坐标的对象。

2 个答案:

答案 0 :(得分:0)

mongoDb GeoJSON object documnetpoint几何结构的基础不正确,coordinates必须是具有2个元素的数组,而不是包含另一个数组的数组

答案 1 :(得分:0)

最后,我修复了更改模型模式的问题。

最初我有这个:

 _id:String,
type:String,
properties:{
    name:String,
    amenity:String,
    popupContent:String
},
geometry:{
    type:String,
    coordinates:[]
}

现在我有了这个

type:String,
    properties:{
        name:String,
        amenity:String,
        popupContent:String
    },
    geometry:{
        type: {type: String, default: 'MultiPoint'},
        coordinates: {type: []}
    }  

我有想要的对象作为回报:

{"properties":{"name":"Coors Field","amenity":"Baseball Stadium","popupContent":"This is where the Rockies play!"},"geometry":{"type":"MultiPoint","coordinates":[[-3.68814468383789,40.5248912033234],[-3.70814468383789,40.5248912033234],[-3.68230819702148,40.5074040815359]]},"_id":"5c03a3da82822133f0406667","type":"Feature","__v":0}