title: Mongoose: Cast to ObjectId failed for value
body: <p>I'm trying to specify the schema of my db in mongoose. At the moment I do this:</p>
  
  <pre><code>var Schema = mongoose.Schema;  
  var today = new Date(2011, 11, 12, 0, 0, 0, 0);
  
  
  var personSchema = new Schema({  
     _id : Number,
     name: { type: String, required: true },  
     tel: { type: String, required: true },  
     email: { type: String, required: true },
     newsitems: [{ type: Schema.Types.ObjectId, ref:'NewsItem'}]
  });
  
  var taskSchema = new Schema({ 
      _id: Number,
      description: { type: String, required: true },  
      startDate: { type: Date, required: true },
      newsitems: [{ type: Schema.Types.ObjectId, ref:'NewsItem'}]
  });
  
  var newsSchema = new Schema({
      _id: Number,
      creator : { type: Schema.Types.ObjectId, ref: 'Person' },
      task : { type: Schema.Types.ObjectId, ref: 'Task' },
      date: { type: Date, required:true },
      loc: {type: String, required: true }  
  });
  
  var NewsItem  = mongoose.model('NewsItem', newsSchema);
  var Person = mongoose.model('Person', personSchema);
  var Task = mongoose.model('Task', taskSchema);
  
  
  
  var tony = new Person({_id:0, name: "Tony Stark", tel:"234234234", email:"tony@starkindustries.com" });
  var firstTask = new Task({_id:0, description:"Get an interview with the president", startDate:today});
  var newsItem1 = new NewsItem({_id:0, creator: tony.id, task: firstTask.id, date: today, loc: "NY"});
  
  newsItem1.save(function (err) {
    if (err) console.log(err);
  
      firstTask.save(function (err) {
          if (err) console.log(err);
      });
  
      tony.save(function (err) {
           if (err) console.log(err);
      }); 
  });
  
  
  
  NewsItem
  .findOne({ loc: "NY" })
  .populate('creator')
  .populate('task')
  .exec(function (err, newsitem) {
    if (err) console.log(err)
      console.log('The creator is %s', newsitem.creator.name);
  })
  </code></pre>
  
  <p>I create the schemas and try to save some data. </p>
  
  <p>The error:</p>
  
  <pre><code>{ message: 'Cast to ObjectId failed for value "0" at path "creator"',
    name: 'CastError',
    type: 'ObjectId',
    value: '0',
    path: 'creator' }
  </code></pre>
  
  <p>I wrote this code based on : <a href="http://mongoosejs.com/docs/populate.html#gsc.tab=0" rel="nofollow noreferrer">http://mongoosejs.com/docs/populate.html#gsc.tab=0</a></p>
  
  <p>The db I try to create looks like this: <a href="https://stackoverflow.com/questions/15747130/specify-schema-in-mongoose">Specify schema in mongoose</a> .</p>
  
  <p>How can I fix this?</p>