ここで特定の学生の詳細を学生IDに基づいて更新しようとしています。findByIdを使用して学生の詳細全体を更新する方法がわかりません。 フロントエンドから更新された値を取得してサーバーに送信できますが、サーバーから更新された値をmongoDBに送信できますが、更新方法はわかりません。 私を助けてください。mongooseを使用してmongodoseでオブジェクト全体を更新する方法
これは私のサーバーのコードです:
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);
});
}
戻り値は未定義です。私はERORRを手に入れています!レスポンスとして –
req.body.IdはMongodbに格納されているIDと同じです(インデックスに使用されるID、24文字の長さ)? –
番号。私はカスタムIDを使用しています –