我想根据学生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 –