title: how to increment an id in mongodb
body: <pre><code>import mongoose from 'mongoose';
  // mongoose Schema is what is used to define attributes for our documents
  var Schema = mongoose.Schema;
  //connect to a MongoDB database
  var db = mongoose.connect('mongodb://127.0.0.1:27017/student');
  //Connection establishment between mongoose and mongodb
  mongoose.connect('connected', function() {
      console.log("database connected successfully")
  });
  
  
  var userSchema = new Schema({
  
      id:{
          type:Number,
              unique:true,
              autoIndexId:true
      },
      Name: {
          type: String,
          required: true,
                  unique:false
      },
      Age: {
          type: Number,
          required: true
      }
  },   {
      collection: ('studentcollection')
  });
  
  var User = mongoose.model('User', userSchema);
  
  function createStudent(name, age, cb) {
      var list = new User({
              id:4,
          Name: name,
          Age: age
      });
  
      list.save(function(err) {
          if (err) return cb(err);
          return cb();
      });
  }
  
  function listStudent(cb) {
      User.find({}, function(err, studentcollection) {
          if (err) return cb(err);
          return cb(null, studentcollection);
      }).select('-__v');
  }
  
  
  exports.createStudent = createStudent;
  exports.listStudent = listStudent;
  
  User.findByIdAndRemove(2,function(err){
      if(err) throw err;
      console.log("deleted");
  });
  </code></pre>
  
  <p>this is my  code, i need to increment the id when ever i receive the data from server it should be unique and also when i delete an  id, the id value must also update. I came across the auto-incremental but when i delete an particular Id it does not update the id. Is their any other method so i can increment id .</p>