findAndModify() giving exception in mongoose findAndModify() giving exception in mongoose mongoose mongoose

findAndModify() giving exception in mongoose


Try this one. This will work.

router.route('/user/:_id/host/:_id/accept/').post(function(req, res) {        Host.findOneAndUpdate({                "_id" : req.body.eventid,                "joinees" : {                        "$elemMatch" : {                                "userid" : req.body.userid                        }                }        }, {                "$set" : {                        "joinees.$.status_code" : 1                }        }, {                "new" : true,                "upsert" : false        }, function(err, host) {                if (err) {                        console.log(err);                        res.json(err);                } else {                        res.json({                                message : "request Accepted",                                requestStatus : 1                        });                }        });});