I have the following mongoose schema
const groupSchema = new mongoose.Schema({
club:{
type: mongoose.Schema.Types.ObjectId,
ref: 'Club',
required:true,
},
group:[{
team:{
type: mongoose.Schema.Types.ObjectId,
ref: 'Team',
required:true,
},
wins:[{
type: mongoose.Schema.Types.ObjectId,
ref: 'Game',
default:[],
}],
points:{
type: Number,
default: function(){
return this.wins.length
}
},
}],
},{timestamps:true})
The issue that I am having is with the default value of the points attribute. It should return this.wins.lenght, but it allows returns 0.
When I tested it with this._id, it confirmed that I am referring to the right object as it was equal to the id of subdocument, yet it does not work with this.wins.length
any suggestions?