title: Using a custom ID for mongoose schema
body: <p>I'm wondering if there is a good approach for assigning custom (user friendly) ID's to a schema. I want my own ID to be something like '1234' not the ObjectID automatically assigned by mongoose. The app I'm creating is a task management app so I want each task created to have an easy to read id which can be entered in a search box and then be brought to that particular task.</p>
  
  <p>My schema</p>
  
  <pre><code>var tickitSchema = Schema({
  title               : String,
  description         : String,
  completed           : Boolean,
  priority            : Number,
  category            : Number,
  customId            : {type: Schema.Types.ObjectId, ref: 'TickitNumber'}, 
  updatedAt           : {type: Date},
  author              : { 
      type            : Schema.Types.ObjectId, 
      ref             : 'User' 
  },
  comments            : [{
      body            : String,
      by              : {
         type         : Schema.Types.ObjectId,
         ref          : 'User'
      }
  }],
  boardToBeDisplayedOn: [{
      type            : Schema.Types.ObjectId,
      ref             : 'Board'
  }]
  </code></pre>
  
  <p>});</p>
  
  <pre><code>var mongoose    = require('mongoose');
  var Schema      = mongoose.Schema;
  
  var tickitNumberSchema = Schema({
      tickitId : Number
  });
  
  module.exports = mongoose.model('TickitNumber', tickitNumberSchema);
  </code></pre>
  
  <p>Then on my server side API (node/express) I have a function for creating a task.</p>
  
  <pre><code>exports.create = function(req, res, next) {
    var tickit = Tickit(req.body);
    tickit.category = 1;
    for(i = 0; i &lt; TickitNumber.length; i++) {
      var tn = TickitNumber[i] + 1;
    }
    if(!req.body.title) {
      res.status(400);
      res.send('Title is required');
    } else {
    var data = [];
    tickit.author = req.user;
    tickit.boardToBeDisplayedOn = req.user.ownsBoard;
    tickit.customId = tn;
  
    tickit.save(function (err, tickit) {
      if (err || tickit === null) { return res.send(err || new Error('Tickit was not saved but there was no error...odd')); }
      async.parallel([
        function(callback) {
          User.findByIdAndUpdate(req.user.id, {$push: {userTickits: tickit}}, {new: true}, function (err, user) {
            if (err) return callback(err);
            data.push(tickit);
            callback();// or whatever else you want to send
          })
        },
  
        function(callback) {
          Board.findByIdAndUpdate(tickit.boardToBeDisplayedOn,{$push: {boardTickits: tickit}}, {new:true}, function(err, board){
            if(err) return res.send(err) ;
            data.push(board);
            callback();
          })
        }
      ], function(err) {
          if(err) return next(err);
  
          res.status(201);
          res.json(tickit);
        });
    });
  }  
  }
  </code></pre>
  
  <p>If anyone knows of a better way of doing this or improving what I've already done it would be really helpful, thanks!</p>