node.js - mongoose subdocuments don't reflect update after Model.findByIdAndUpdate -


so i've got schema looks like:

var projectschema = new mongoose.schema({     scrum_master_id: {type: mongoose.schema.types.objectid, ref: 'user'},     developers: [{type: mongoose.schema.types.objectid, ref: 'developer'}],     scrums: [{type: mongoose.schema.types.objectid, ref: 'scrum'}],     created_at: {type: date, default: date.now},     meta: {         trello_board_id: string,         basecamp_url: string     },     description: string,     title: string   }); 

i can send express server , update properly. route in question looks like:

.put(jwt.protect, function (req, res) {      project.findbyidandupdate(req.params.id, {$set: req.body}, function (err, project) {       console.log(project);       res.json(project);     }); }) 

the issue have sub documents developers aren't updated in project variable being passed findbyidandupdate callback. documents updated in database, not in callback of update function. how can refresh sub documents reflect database has?

findbyidandupdate takes options parameter can pass {new:true} , it'll return modified document:

project.findbyidandupdate(req.params.id, {$set: req.body}, {new: true}, function (err, project) {   console.log(project);   res.json(project); }); 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

python - How to remove the Xframe Options header in django? -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -