0
var CandidateProfileSchema = new Schema({
Skills: {
programmingLang: [{text: String}],
scriptingLang: [{text: String}],
tools: [{text: String}],
ide: [{text: String}],
},
//more fields
});
exports.updateOptPrefs = function(req, res) {
console.log(req.body);
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.Skills.programmingLang= req.body.Skills.programmingLang;
candidateProfile.Skills.scriptingLang= req.body.Skills.scriptingLang;
candidateProfile.Skills.tools=req.body.Skills.tools;
candidateProfile.Skills.ide=req.body.Skills.ide;
//.... other fields
candidateProfile.save(function (err) {
if (err) { return handleError(res, err); }
return res.json(200, candidateProfile);
});
});
};
不知何故,這隻複製MongoDB文檔中的programmingLang字段。我們在這個問題上花了大約5個小時,如果有人能指出我們在這裏犯的錯誤,我們將非常高興。更新保存部分數據
或者如果你想只更新技能: 'candidateProfile.Skills = _.extend(candidateProfile.Skills,req.body.Skills);' – teleaziz 2015-01-04 19:49:01
謝謝teleaziz,你救了我們大量的時間:) – Vineet 2015-01-04 21:13:35
我有一個更大的candidateProfile模式 CandidateProfile({ 技能:{....} 其他:[{ typeExp:字符串, 組織:字符串, 開始日期:字符串, 結束日期:字符串, 作用:字符串, description:字符串, 成就:字符串 }], //更多字段 我基本上更新每個部分像技能或其他在每個呼叫中的每個部分。當我在上面的技能部分使用您的建議合併時,它的效果很好。我嘗試使用與上面的其他Exp相同的代碼,並且獲得具有相同數據的2行。 你能看到問題嗎? – Vineet 2015-01-04 23:32:24