给出我数据库中的以下文档:
{
"_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中执行相同的查询,则会得到带有坐标的对象。
答案 0 :(得分:0)
mongoDb GeoJSON object documnet的point
几何结构的基础不正确,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}