title: Mongoose, CastError: Cast to Array failed for value when trying to save a model that contains a model
body: <p>I am trying to create the model for my mongodb database using mongoose. This is what I am trying to do: </p>
  
  <pre><code>var Class = mongoose.model('Class', {className: String, marks: [{type: Number}], grades: [{type: Number}]});
  var User = mongoose.model('User', {email: String, classes: [Class] });
  
  
  //Lets create a new user
  var class1 = new Class({className: 'aaa', marks: [72, 88, 63], grades: [30, 40, 30]});
  var user1 = new User({email: 'aaa@some.com', classes: [class1]});
  </code></pre>
  
  <p>Saving <code>class1</code> seems to work okay but when I check mongodb, this is displayed: </p>
  
  <pre><code>{ 
    "_id" : ObjectId("someId"), 
    "className" : "TEST1234", 
    "grades" : [ 30, 40, 30 ], 
    "marks" : [ 72, 88, 63 ], 
    "__v" : 0 
  }
  </code></pre>
  
  <p>What is <code>"__v : 0"</code>?</p>
  
  <p>Saving the user is not successful at all, this is the following error: </p>
  
  <blockquote>
    <p>ValidationError: CastError: Cast to Array failed for value "{ marks: [ 72, 88, 63 ],
      grades: [ 30, 40, 30 ],
      _id: someId,
      className: 'TEST1234' }" at path "classes"
    `  </p>
  </blockquote>
  
  <p>What exactly does the error mean? Why is it casting anything to a array? Shouldn't <code>classes: [Class]</code> be an array of type <code>class</code>?</p>