findByIdAndUpdate throwing cast error when I try and update a property to null

56 views
Skip to first unread message

Mongo Rookie

unread,
Jun 26, 2013, 10:15:11 AM6/26/13
to mongoo...@googlegroups.com
Schema:
var SomeSchema = new Schema({
    name: { type: String, required: true, unique: true },
    description: { type: String, required: false }
  },{ 
    versionKey: false
  }
);

// In this case the client did not pass me a description, which is ok cause this property is not required.
// Why would the update fail?
var update = {name: someName, description: someDescription}; 
findByIdAndUpdate(id, update, function(err, something) { ...

Here is the error, yup cannot cast null/undefined to a String but why try?
CastError: Cast to string failed for value "undefined" at path "description"
Reply all
Reply to author
Forward
0 new messages