MongooseJS Not saving to array properly

I want to append a value into my Mongoose array but my array never seems to update. I do the following:

In my controller, I append an eventName into the array eventsAttending like so:

  $scope.currentUser.eventsAttending.push(event.eventName);
  $http.put('/api/users/' + $scope.currentUser._id, $scope.currentUser)
    .success(function(data){
      console.log("Success. User " + $scope.currentUser.name);
    });

I try to update the array like so:

// Updates an existing event in the DB.
exports.update = function(req, res) {
  if(req.body._id) { delete req.body._id; }
  User.findById(req.params.id, function (err, user) {
    if (err) { return handleError(res, err); }
    if(!user) { return res.send(404); }
    user.markModified('req.body.eventsAttending');
    user.save(function (err) {
      if (err) { return handleError(res, err);}
      return res.json(200, user);
    });
  });
};

But my array never seems to update. I've also tried the following:

// Updates an existing event in the DB.
exports.update = function(req, res) {
  if(req.body._id) { delete req.body._id; }
  User.findById(req.params.id, function (err, user) {
    if (err) { return handleError(res, err); }
    if(!user) { return res.send(404); }
    var updated = _.merge(user, req.body);
    updated.markModified('eventsAttending');
    updated.save(function (err) {
      if (err) { return handleError(res, err);}
      return res.json(200, user);
    });
  });
};

With this approach, my array updates properly, but when I try to perform the http put after one time, I get an error saying Error: { [VersionError: No matching document found.] message: 'No matching document found.', name: 'VersionError' }

Here is my UserSchema:

var UserSchema = new Schema({
  name: String,
  username: String,
  eventsAttending: [{ type: String, ref: 'Event'}],
});

If anyone could help that would be much appreciated.

My guess is the object returning from _.merge is no longer a Mongoose model and some information is getting lost in the transform. I would try manually setting all of the fields coming from the request and use events.attending.push() to add to the array, then saving the updated object and see what happens.

Your first example with markModified looks wrong. Looking at the documentation it should be the name of the field that is modified and it appears that you've put the source location for it.

user.markModified('user.eventsAttending')

However that should not be necessary if you use the push method as Mongoose overrides the built-in array function to track changes.