title: is there a way to auto generate ObjectId when a mongoose Model is new'ed?
body: <p>is there a way to declare a Model schema in mongoose so that when the model is new'ed the _id field would auto-generate?</p>
  
  <p>for example:</p>
  
  <pre><code>var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  var ObjectIdSchema = Schema.ObjectId;
  var ObjectId = mongoose.Types.ObjectId;
  
  var PersonSchema = new Schema({
      _id:            ObjectIdSchema,
      firstName:      {type: String, default: 'N/A'},
      lastName:       {type: String, default: 'N/A'},
      age:            {type: Number, min: 1}
  });
  
  var Person = mongoose.model('Person', PersonSchema);
  </code></pre>
  
  <p>at first, i thought great!, i'll just do</p>
  
  <pre><code>_id:    {type:ObjectIdSchema, default: new ObjectId()}
  </code></pre>
  
  <p>but of course that doesn't work, because new ObjectId() is only called on initialize of schema. so calling new Persion() twice creates two objects with the same _id value.</p>
  
  <p>so is there a way to do it so that every time i do "new Person()" that a new ObjectId() is generated?</p>
  
  <p>the reason why i'm trying to do this is because i need to know the value of the new person's _id value for further processing. </p>
  
  <p>i also tried:</p>
  
  <pre><code>var person = new Person({firstName: "Joe", lastName: "Baz"});
  person.save(function(err, doc, num){
      console.log(doc._id);
  });
  </code></pre>
  
  <p>even then, doc doesn't contain the ObjectId. but if i look in the database, it does contain it. </p>
  
  <p>p.s. i'm using mongoose 2.7.1</p>
  
  <p>p.p.s. i know i can manually create the ObjectId when creating the person as such:</p>
  
  <pre><code>var person = new Person({_id: new ObjectId(), firstName: "Joe", lastName: "Baz"});
  </code></pre>
  
  <p>but i rather not have to import ObjectId and have to new it every time i want to new a Person. guess i'm used to using the java driver for mongodb, where i can just create the value for the _id field in the Model constructor.</p>