Reputation: 149
I have a studentRollNumber with me. And I wish to modify a field in student record with that particular roll number. How can I do this. I tried the below code. I would like to fetch the record with the studentnumber 123 and modify its status field to 0
function updateRecord(){
var studentNumber = '123';
var filter = { studentNum: studentNumber };
var newStatus = Number(0);
var modifyStatus ={status : newStatus}
Student.findOneAndUpdate(filter,modifyStatus,(err)=>{
if(!err){
console.log('updation to db sucess')
}
})
Upvotes: 0
Views: 33
Reputation: 57
You can do something like following,
function updateRecord(){
var studentNumber = '123';
var filter = { studentNum: studentNumber };
var newStatus = Number(0);
var modifyStatus = {$set:{status:newStatus}}
Student.findOneAndUpdate(filter , modifyStatus, {new: true})
.then(() => console.log('Record Update Successfully');
}
Upvotes: 1