How to add unique value to mongoose subdocument with nestjs?

Viewed 168

I want to convert a mongoose schema from my express api to nest js.

const levelSchema = new Schema(
  {
    title: {
      type: String,
      required: true,
    },
  },
  {
    timestamps: true,
  }
);
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";

export type LevelDocument = Level & Document;

@Schema({
  timestamps: true,
})
export class Level {
  @Prop({
    type: [
      {
        locale: { type: String, enum: ["fr", "en"] },
        title: { type: String, unique: true },
      },
    ],
  })
  translations: object[];

  @Prop({ default: false })
  visibility: Boolean;
}

export const LevelSchema = SchemaFactory.createForClass(Level);

It works as expected but for some reason I'm not able to add unique key for the title ? I do not have any error, it just seems to ignore the unique: true rule.

0 Answers
Related