Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Multiple field is not the array in nestjs mongoose Schema

I wanted to connect multiple videos with foreign keys on my schema

  @Prop({
    type: mongoose.Schema.Types.ObjectId,
    ref: Video.name,
  })
  videos: Video[];

Btw, the result is not returning Array. I was returning 1 video (foreign key).

videos: "xxxxxx"

I want the below result

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

videos: ['xxxx', 'rrrr', 'yyyyy', ...]

How can I solve this issue?

>Solution :

You can fix this issue easily.

  @Prop({
    type: [
      {
        type: mongoose.Schema.Types.ObjectId,
        ref: Video.name,
        autopopulate: true,
      },
    ],
  })
  videos: Video[];

You have to define type as an array in the schema.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading