title: ERROR: ValidationError: CastError: Cast to ObjectID failed for value
body: <p><strong>SITUATION:</strong></p>
  
  <p>It seems I must have made a mistake in my Mongoose Model or in one of the parameters that are passed to the route.</p>
  
  <p>I am fairly new to the angular2 architecture, so the mistake might be quite obvious.</p>
  
  <p><strong>ERROR:</strong> </p>
  
  <pre><code>  ERROR: ValidationError: CastError: Cast to ObjectID failed for value "{ title: 'das',
        username: 'John',
        choice1: 'FSDAFASDF',
        choice2: 'FDSAFD',
        counter1: 11,
        counter2: 0,
        pollId: '5920598ade7567001170c810',
        userId: '591c15b3ebbd170aa07cd476' }" at path "poll"
  </code></pre>
  
  <hr>
  
  <p><strong>CODE:</strong></p>
  
  <p><strong>route</strong></p>
  
  <pre><code>router.patch('/', function (req, res, next) {
      var decoded = jwt.decode(req.query.token);
      User.findById(decoded.user._id, function (err, user) {
        user.votes = req.body.votes;
        user.save(function(err, result) {
            if (err) {
                console.log("ERROR: "+err);
                return res.status(500).json({
                    title: 'An error occurred',
                    error: err
                });
            }
            res.status(201).json({
                poll: 'Vote Saved',
                obj: result
            });
        });
     });
  });
  </code></pre>
  
  <p><strong>models/user:</strong></p>
  
  <pre><code>var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  var mongooseUniqueValidator = require('mongoose-unique-validator');
  
  var schema = new Schema({
      firstName: {type: String, required: true},
      lastName: {type: String, required: true},
      password: {type: String, required: true},
      email: {type: String, required: true, unique: true},
      polls: [{type: Schema.Types.ObjectId, ref: 'Poll'}],
      votes: [{
        poll: {type: Schema.Types.ObjectId, ref: 'Poll'},
        choice: {type: Number},
      }],
  });
  
  schema.plugin(mongooseUniqueValidator);
  
  module.exports = mongoose.model('User', schema);
  </code></pre>
  
  <p><strong>models/poll</strong></p>
  
  <pre><code>var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  
  var User = require('./user');
  
  var schema = new Schema({
      title: {type: String, required: true},
      choice1: {type: String, required: true},
      choice2: {type: String, required: true},
      counter1: {type: Number, required: true},
      counter2: {type: Number, required: true},
      user: {type: Schema.Types.ObjectId, ref: 'User'}
  });
  
  schema.post('remove', function (poll) {
      User.findById(poll.user, function (err, user) {
          user.polls.pull(poll);
          user.save();
      });
  });
  
  module.exports = mongoose.model('Poll', schema);
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>router.patch('/', function (req, res, next) {
      var decoded = jwt.decode(req.query.token);
      console.log("VALID ID ? :"+mongoose.Types.ObjectId.isValid(decoded.user._id));
      console.log("DECODED USER ID:"+ decoded.user._id);
      User.findByIdAndUpdate(decoded.user._id, {votes: req.body.votes}, function (err, user) {
        user.save(function(err, result) {
            if (err) {
                console.log("ERROR: "+err);
                return res.status(500).json({
                    title: 'An error occurred',
                    error: err
                });
            }
            res.status(201).json({
                poll: 'Vote Saved',
                obj: result
            });
        });
     });
  });
  </code></pre>