GeoJSON 数据保存但查询时 returns 未定义
GeoJSON data saving but returns undefined when queried
我有以下架构
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 的数据保存为从我的架构中看到的对象,其格式与我从开放层 api 收到的格式相同。我猜这是导致我的 findByIdAndRemove(id, callback); 到 return a
TypeError: Cannot read property '562bc2b5fde8999f2995e61c' of undefined
我该如何解决这个问题,以便我可以执行除在此架构上保存以外的其他操作
您似乎将 map.course
保存为 String
(JSON 数据),而不是 Object
。
如果那是 ol.format.GeoJSON
创建的 GeoJSON,请考虑使用 writeFeatureObject
instead of writeFeature
。它们 return 相同的结果,但第一个是实际的 JS 对象,第二个是带有 JSON.
的字符串
我有以下架构
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 的数据保存为从我的架构中看到的对象,其格式与我从开放层 api 收到的格式相同。我猜这是导致我的 findByIdAndRemove(id, callback); 到 return a
TypeError: Cannot read property '562bc2b5fde8999f2995e61c' of undefined
我该如何解决这个问题,以便我可以执行除在此架构上保存以外的其他操作
您似乎将 map.course
保存为 String
(JSON 数据),而不是 Object
。
如果那是 ol.format.GeoJSON
创建的 GeoJSON,请考虑使用 writeFeatureObject
instead of writeFeature
。它们 return 相同的结果,但第一个是实际的 JS 对象,第二个是带有 JSON.