node.js - Mongoose 查询不返回 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 中执行相同的查询,我会得到带有坐标的对象。
解决方案
最后,我修复了它更改模型架构。
最初我有这个:
_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}
推荐阅读
- python - 刻度在颜色栏上未正确显示
- python - 跨多个进程的共享字典未更新
- python - 如何修复python中的“名称'self'未定义”错误?
- visual-studio - Angular 项目无法在具有 Visual Studio 2019 的 docker 上运行
- javascript - 去抖功能单元测试
- c# - 如何访问嵌套命名空间以避免在 .NET 中完全限定
- python - 如果在 Python 3.7 中运行超过一次,函数将不再起作用
- python - 按值排序字典,然后按键
- c++ - 确定每次更改源文件时重新配置 CMake 的原因
- python - 识别其中存在特定字符的文件并重命名文件