我想根據學生id更新這裏的特定學生詳細信息。我不知道如何使用findById更新整個學生的詳細信息。 我能夠從前端獲取更新值並將其發送到服務器,但從服務器我能夠發送更新值到mongoDB,但我不知道如何更新。 請幫我一把。如何使用貓鼬更新mongodb中的整個對象
這是我的服務器代碼:
server.post('/update',urlencodedParser,function(req,res){
var response={
Id:req.body.Id,
Fname : req.body.Fname,
age:req.body.age,
Lname : req.body.Lname,
dob : req.body.dob,
pob : req.body.pob,
month : req.body.month,
nation : req.body.nation,
mothertongue : req.body.mothertongue,
bloodgroup : req.body.bloodgroup,
fatherfname : req.body.fatherfname,
fatherlname : req.body.fatherlname,
occupation : req.body.occupation,
placeofwork : req.body.placeofwork,
officaladd : req.body.officaladd,
emailid : req.body.emailid,
phoneno : req.body.phoneno,
mobileno : req.body.mobileno,
motherfname : req.body.motherfname,
motherlname : req.body.motherlname,
motheroccupation : req.body.motheroccupation,
motherplaceofwork : req.body.motherplaceofwork,
motherofficaladd : req.body.motherofficaladd,
motheremailid : req.body.motheremailid,
motherphoneno : req.body.motherphoneno,
mothermobileno : req.body.mothermobileno,
adress : req.body.adress,
emergencyadress : req.body.emergencyadress,
emergencyphone1 : req.body.emergencyphone1,
emergencyphone2 : req.body.emergencyphone2,
relationship1 : req.body.relationship1,
relationship2 : req.body.relationship2
}
databaseInterface.updateStudent(response, function(err, valss){
if(err) res.send('ERROR!');
console.log(valss);
res.send(valss);
})
})
這是我的貓鼬代碼:
function updateStudent(response,callback) {
console.log(response)
User.findById(response.Id, function(err, studentcollection2) {
if (err) return callback(err);
studentcollection2 = response;
return callback(null, studentcollection2);
});
}
它返回undefined。我正在獲得ERORR!作爲迴應 –
req.body.Id等同於存儲在Mongodb中的id(用於索引的id,24個字符長)? –
沒有。我正在使用自定義ID –