OverwriteModelError while using Mongoose discriminators in NestJS OverwriteModelError while using Mongoose discriminators in NestJS mongoose mongoose

OverwriteModelError while using Mongoose discriminators in NestJS


I solved this problem by replacing Mongoose.forFeature with Mongoose.forFeatureAsync, hope this will help:

MongooseModule.forFeatureAsync([  {    name: Event.name,    useFactory: () => {      return EventSchema;    },    discriminators: [      { name: ClickedLinkEvent.name, schema: ClickedLinkEventSchema },      { name: SignUpEvent.name, schema: SignUpEventSchema },    ],  },]),