我有以下架构
var RaceSchema = new Schema({
account: {
_id: String,
name: String,
country: String
},
raceName: String,
raceStartTime: Date,
timezone: Number,
trackTimeStart: Date,
trackTimeFinish: Date,
sponserImageURL: Array,
map: {
center: Array,
course: Object,
zoomLevel: Number
},
boats: [{
_id: String,
handicaps: [{
name: String,
division: Number,
rating: Number,
correctedTime: Number,
place: Number
}]
}],
dtg: Number,
eta: Date,
finishTime: Date,
socialMedia: [{
name: String,
link: String
}],
createdAt: { type: Date, default: new Date },
updatedAt: Date
}, {
collection: 'race'
});
我用它来存储GeoJson数据以及架构中显示的其他一些信息。我以下列格式保存数据(它是我在保存时从服务器获得的响应)
{
"_id": "562bc48bfde8999f2995e61d",
"raceStartTime": "2015-10-29T17:48:00.000Z",
"trackTimeStart": "2015-10-24T17:48:00.000Z",
"trackTimeFinish": "2015-10-24T17:48:00.000Z",
"raceName": "Test ",
"timezone": -4.5,
"__v": 1,
"updatedAt": "2015-10-24T17:49:16.912Z",
"createdAt": "2015-10-24T17:39:45.587Z",
"socialMedia": [],
"boats": [{
"_id": "55f6c2d39a2496d01d000002",
"handicaps": []
}],
"map": {
"center": [78.4651562, 17.4079808],
"course": "{\"type\":\"LineString\",\"coordinates\":[[8639830.18113004,2037505.4259696582],[8738281.073561348,1972075.3297575472],[8619650.805662755,1928659.0976915671],[8645333.647166574,1981859.2693780498],[8598248.437742906,2021606.5240863415]]}",
"zoomLevel": 8
},
"sponserImageURL": [],
"account": {
"_id": "55a7c944d65763c23d11dd96",
"name": "Huy Tran"
},
"id": "562bc48bfde8999f2995e61d"
}
我将 map.course 的数据保存为对象,从我的架构中看到的格式与我从open layers api收到的格式相同。我猜这是导致我的 findByIdAndRemove(id,callback); 返回
TypeError: Cannot read property '562bc2b5fde8999f2995e61c' of undefined
如何解决此问题,以便除了保存此架构外,我还可以执行其他操作
答案 0 :(得分:0)
您似乎将map.course
保存为String
(JSON数据),而不是Object
。
如果是由ol.format.GeoJSON
创建的GeoJSON,请考虑使用writeFeatureObject
代替writeFeature
。它们返回相同的结果,但第一个是实际的JS对象,秒是带有JSON的String。