【发布时间】:2014-07-13 20:13:45
【问题描述】:
我想在 express 中更新嵌套对象时遇到问题。这是我的代码:
.put(function(req, res) {
Place.findById(req.params.place_id, function(err, place) {
if (err)
res.send(err);
if (typeof req.body.zip !== 'undefined') {
place.zip = req.body.zip;
}
if (typeof req.body.loc !== 'undefined') {
place.loc = req.body.loc;
}
if (typeof req.body.coordinates !== 'undefined') {
place.coordinates = req.body.coordinates;
}
place.save(function(err) {
if (err)
res.send(err);
res.json({ message: 'Place updated!' });
});
});
});
当我想更新 zip 时,它正在工作,但我无法修改坐标。我也尝试了place.loc.coordinates。我正在使用 curl 进行更新,也许那个命令是错误的。我试过了
curl -X PUT -d loc.coordinates=[1.3,3.2] 'http://localhost:8080/api/places/A38'
curl -X PUT -d coordinates=[1.3,3.2] 'http://localhost:8080/api/places/A38'
命令。
我的架构是:
var placeSchema = new Schema({
_id: String,
zip: Number,
loc: {
type: { type: String }
, coordinates: []
}
});
谁能帮帮我?
【问题讨论】: