Answer the question
In order to leave comments, you need to log in
Why is Typegoose population not working?
I have two models:
class Pupil {
@Prop({ type: String, required: true, unique: false })
public name!: string
@Prop({ type: String, required: true, unique: false })
public surname!: string
@Prop({ type: String, required: true, unique: false })
public midname!: string
@Prop({ type: String, required: true, unique: false })
public age!: string
@Prop({ type: String, required: true, unique: false })
public gender!: string
@Prop({ type: String, required: true, unique: false })
public phone!: string
@Prop({ type: String, required: false, unique: false })
public parentPhone!: string
@Prop({ type: String, required: true, unique: false })
public discord!: string
}
class Group {
@Prop({ type: String, required: true, unique: true })
public GROUP_NAME!: string
@Prop({ type: Number, required: true, unique: false })
public LEVEL!: number
@Prop({ type: String, required: true, unique: false })
public TUTOR!: string
@Prop({ type: Number, required: true, unique: false })
public PLACES!: number
@Prop({
type: Schema.Types.Array,
ref: 'Pupil',
unique: false,
default: []
})
public PUPILS!: Ref<Pupil>[]
}
{
"GROUP_NAME": "Имя Группы",
"TUTOR": "Преподаватель",
"LEVEL": 4,
"PLACES": 3,
"PUPILS": ["60b8bd8ea379d8001f1e7700", "60b8c143a379d8001f1e7701"]
}
await Group.find().populate('PUPILS', 'Pupil')
{
"PUPILS": [],
"_id": "60b9755dee93c303b35d0afb",
"GROUP_NAME": "Имя Группы",
"TUTOR": "Преподаватель",
"LEVEL": 4,
"PLACES": 3,
"__v": 0
}
Answer the question
In order to leave comments, you need to log in
It solved itself, I didn’t even understand what had changed in my code
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question