The great MongoDB doesn’t generate _id for array elements automatically unless it’s schema is defined separately. The below is the example to define a separate schema for the subdocuments.
const arrayElementSchema = new mongoose.Schema({...}); const mainDocument = new mongoose.Schema({ children: [arrayElementSchema] })
With the above Schema, MongoDB will generate _id for every element you (more…)