【发布时间】:2015-03-02 12:35:36
【问题描述】:
我有这个架构
var CandidateProfileSchema = new Schema({
OtherExp: [{
typeExp:String,
organization: String,
startDate: String,
endDate: String,
role: String,
description: String,
achievements: String
}],
//more fields
});
这是我的控制器函数,用于在架构中放置/更新 OtherExp 字段。
exports.updateOtherExp = function(req, res) {
if(req.body._id) { delete req.body._id; }
CandidateProfile.findOne({userId:req.params.id}, function (err, candidateProfile) {
if (err) { return handleError(res, err); }
if(!candidateProfile) { return res.send(404); }
candidateProfile.other= _.extend(candidateProfile.other, req.body.other);
candidateProfile.save(function (err) {
if (err) { return handleError(res, err); }
return res.json(200, candidateProfile);
});
});
};
我的数据是 第 1 行:a1、a2、a3、a4、a5、、a6、a7 第 2 行:b1、b2、b3、b4、b5、、b6、b7
问题是保存到我的 mongodb 集合的数据是第一行的重复 第 1 行:a1、a2、a3、a4、a5、、a6、a7 第 2 行:a1、a2、a3、a4、a5、、a6、a7
谁能看到可能是什么问题? 相同的代码适用于我的架构的其他部分,我没有像这个一样嵌套数据。
这是来自我的 CandidateProfile / index.js
router.put('/:id', controller.update);
router.put('/:id/skills', controller.updateSkills);
router.put('/:id/otherExp', controller.updateOtherExp);
【问题讨论】:
-
我会使用节点检查器来确保
candidateProfile.other和req.body.other是您期望的值。
标签: javascript node.js mongodb mongoose lodash