title: How to set _id to db document in Mongoose?
body: <p>I'm trying to dynamically create _id's for my Mongoose models by counting the documents in the db, and using that number to create the _id (assuming the first _id is 0). However, I can't get the _id to set from my values. Here's my code:</p>
  
  <pre><code>//Schemas
  var Post = new mongoose.Schema({
      //_id: Number,
      title: String,
      content: String,
      tags: [ String ]
  });
  
  var count = 16;
  
  //Models
  var PostModel = mongoose.model( 'Post', Post );
  
  app.post( '/', function( request, response ) {
  
      var post = new PostModel({
          _id: count,
          title: request.body.title,
          content: request.body.content,
          tags: request.body.tags
      });
  
      post.save( function( err ) {
          if( !err ) {
              return console.log( 'Post saved');
          } else {
              console.log( err );
          }
      });
  
      count++;
  
      return response.send(post);
  });
  </code></pre>
  
  <p>I've tried to set the _id a number of different ways, but it's not working for me. Here's the latest error:</p>
  
  <pre><code>{ message: 'Cast to ObjectId failed for value "16" at path "_id"',
    name: 'CastError',
    type: 'ObjectId',
    value: 16,
    path: '_id' }
  </code></pre>
  
  <p>If you know what's going on, please let me know.</p>