我使用GeoJson将一些带有timeStamp的坐标保存到Mongoose数据库,我定义了这样的模型:
var positionSchema = mongoose.Schema({
position: [{
properties: {
timeStamp: Date
},
geometry: {
type: {
type: String,
default: 'Point'
},
coordinates: {
type: [Number]
}
}
}]
});
数据从API发送如下:
position.findByIdAndUpdate(values.geometries, {
$push: {
position: {
properties: request.payload.timeStamp,
geometry: lastLocation
}
}
}
lastLocation是:
lastLocation = {
type: 'Point',
coordinates: [
request.payload.position.longitude,
request.payload.position.latitude
]
};
当我在路线上发帖时,坐标会正确保存,但timeStamp不会保存在文档中。
答案 0 :(得分:2)
在此代码中:
position.findByIdAndUpdate(values.geometries, {
$push: {
position: {
properties: request.payload.timeStamp,
geometry: lastLocation
}
}
}
当日期值实际位于properties
properties.timeStamp
的日期
所以你可以改用
position.findByIdAndUpdate(values.geometries, {
$push: {
position: {
'properties.timeStamp': request.payload.timeStamp,
geometry: lastLocation
}
}
}