How to require a nested json object in Mongoose Schema How to require a nested json object in Mongoose Schema express express

How to require a nested json object in Mongoose Schema


Update:You can use the Subdocument apporach

const extraDataSchema = new mongoose.Schema({  brand: {    type: String,    required: true,    minlength: 1,    maxlength: 255  },  quantity: {    type: Number,    required: true,    minlength: 1,    maxlength: 10  }});const productSchema = new mongoose.Schema({  name: {    type: String,    required: true,    minlength: 1,    maxlength: 255  },  extraData: {    type: extraDataSchema, required: true  }});


Check out the Mongoose documentation, In this link you can find an explanation on how to add required to nested properties().
I believe you will need a sub-schema for the nested properties.