Mongoose JS path default generating id Mongoose JS path default generating id mongoose mongoose

Mongoose JS path default generating id


You can do this by defining a default property for the activationId field that's the ObjectId constructor function:

var userSchema = new mongoose.Schema({  fullName: {    type: String,    required: true,    index: true  },  activationId: {    type: mongoose.Schema.ObjectId    default: mongoose.Types.ObjectId  }});