I have a simple mongodb model that i want to update.
const ProfileScheme = Schema({
nationality:{
nation: {type: String,lowercase: true, default: null},
town: {type: String,lowercase: true, default: null},
privacy: {type: Number, min:1, max:3, default: 2}
},///etc
I found out that updating the nation document is difficult than expected. Can anyone help please. Because I have try this.
let nationality = req.body.nationality,
privacy = req.body.privacy; res.redirect(req.get('referer'));
updateNationality(profile, nationality, privacy,
function(err, info){
if(err){next(err);}
console.log(info);
});
res.redirect(req.get('referer'));
updateNationality: function(profile,nation, privacy, cb){
let nationality = {};
nationality.nation = nation;
nationality.privacy = privacy;console.log(nationality);console.log("Profile is loading "+profile);// All the log are showing the expected data
Profile.update(profile.nationality, {$set: { 'profile.$.nationality': nationality } }, cb); //this is not working
},