【发布时间】:2015-12-19 21:13:07
【问题描述】:
我有一个用于 geoJSON 多边形对象的猫鼬模式,结构如下:
var polygonZoneSchema = new mongoose.Schema({
location: {
'type': {
type: String,
enum: "Polygon",
default: "Polygon"
},
coordinates: {
type: [[[Number]]]
}
},
zoneType: ObjectId,
riskiness: {
type: Number,
default: 0
}
});
在我的控制器中,我有一个列出所有多边形的函数:
polyZone.find({}).exec(function (err, collections) {
console.log(collections[0].location.coordinates);
if (err) {
res.status(400);
return res.send({reason: err.toString()});
}
res.send(collections);
});
当通过 mongo 命令行检查我的数据库时,该集合包含:
{
"_id": ObjectId("55fb6e7ab228f7343367116d"),
"location": {
"type": "Polygon",
"coordinates": [
[
[0, 0],
[0, 1],
[1, 1],
[1, 0],
[0, 0]
]
]
}
} {
"_id": ObjectId("55fb6e7ab228f7343367116e"),
"location": {
"type": "Polygon",
"coordinates": [
[
[1, 1],
[1, 2],
[2, 2],
[2, 1],
[1, 1]
]
]
}
}
但是,当使用我的控制器函数时,返回的对象有一个空坐标数组:
[
{
"_id": "55fb6e7ab228f7343367116d",
"riskiness": 0,
"location": {
"coordinates": [],
"type": "Polygon"
}
},
{
"_id": "55fb6e7ab228f7343367116e",
"riskiness": 0,
"location": {
"coordinates": [],
"type": "Polygon"
}
}
]
这和猫鼬有关吗?我该如何解决?
【问题讨论】: