this is my model.Here i am receiving an object from the server called response. Now i need to update the data base with this response object.
But the problem is i can only update the variables but not the objects like father.
Father is one object now i need to update father's firstname. But its giving me error if i use Father.Firstname saying unexpected token.
please help me out how to overcome this problem..
var User = mongoose.model('User', userSchema);
function createStudent(response) {
console.log(response);
var list = new User({
Firstname : response.Fname,
Age : response.age,
Lastname : response.Lname,
Father.Firstname : response.fatherfname,
Father.Lastname : response.fatherlname,
Father.Occupation : response.occupation,
Father.PlaceOfWork : response.placeofwork,
Father.OfficialAddress : response.officaladd,
Father.EmailId : response.emailid,
Father.PhoneNo : response.phoneno,
Father.MobileNo : response.mobileno,
});
list.save();
}
If you need to use the dot(.)
character in you object key names then you need to enclose it withing double("")
or single('')
quotes like you do with strings.
So write your code like this -
"Father.Firstname" : response.fatherfname,
instead of
Father.Firstname : response.fatherfname,