R
R
Rag'n' Code Man2021-06-04 03:57:32
typescript
Rag'n' Code Man, 2021-06-04 03:57:32

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>[]
}


- Student and group A group

is created with the following request:
{
  "GROUP_NAME": "Имя Группы",
  "TUTOR": "Преподаватель",
  "LEVEL": 4,
  "PLACES": 3,
  "PUPILS": ["60b8bd8ea379d8001f1e7700", "60b8c143a379d8001f1e7701"]
}


The pupils field stores the _id array of students from the Pupils collection.
I want to make a population of these IDs when a group/groups are requested from my server.

I do it like this: And it returns me an object like this:
await Group.find().populate('PUPILS', 'Pupil')

{
  "PUPILS": [],
  "_id": "60b9755dee93c303b35d0afb",
  "GROUP_NAME": "Имя Группы",
  "TUTOR": "Преподаватель",
  "LEVEL": 4,
  "PLACES": 3,
  "__v": 0
}


I expected that I would receive an array containing 2 student objects from the Pupils collection, but an empty array arrived.

I re-read all the documentation, went around the entire StackOverflow, but did not find anything ... And if I did, then everything was either the same, or on JS without Typegoose.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rag'n' Code Man, 2021-06-06
@iDmitriyWinX

It solved itself, I didn’t even understand what had changed in my code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question