Mongoose doesn't save nested Object in another nested Object Mongoose doesn't save nested Object in another nested Object mongoose mongoose

Mongoose doesn't save nested Object in another nested Object


mongoose.Schema.Types.Day and mongoose.Schema.Types.Match are undefined so those array fields that reference them are ending up as Mixed types instead which don't save unless you explicitly mark them modified.

You need to make those schemas available between the model definitions and then use those in your definitions instead. For example:

var matchSchema = new mongoose.Schema({  team1: {    type: Schema.ObjectId,    ref:'Team'  },  team2: {    type: Schema.ObjectId,    ref: 'Team'  },  score: [Number]});var daySchema = new mongoose.Schema({   _id: Number,   matches:[matchSchema]});var groupSchema = new mongoose.Schema({   name: String,   days:[daySchema],});