nextJs multiple schemas for the same collection

Viewed 14

I would like to define 2 schmeas that are defined for the same collection.

module:

@Module({
  imports: [
    MongooseModule.forFeature([
      { name: 'Exercise', schema: ExerciseSchema, collection: 'exercises' },
      {
        name: 'Exercise', 
        schema: ExerciseTemplateSchema,
        collection: 'exercises',
      },
    ]),
  ],
  controllers: [],
  providers: [ExerciseService],
  exports: [ExerciseService],
})
export class ExerciseModule {}

service:

    @Injectable()
    export class ExerciseService extends GenericCrudService<ExerciseDocument | 
                                                            ExerciseTemplateDocument
    > {
      constructor(
        @InjectModel('Exercise')
        readonly exercise: Model<ExerciseDocument | ExerciseTemplateDocument>,
      ) {
        super(exercise);
      }
}

The difference between the schemas is that the template schema does not have two fields that are mandatory in the exercise schema.

If I now create a document via the service, these 2 fields are not created. Only one scheme is accepted at a time.

How do i define this correctly in nestJS?

Thanks in advance!

Best wishes

0 Answers
Related