YuriGor / mongoose-slug-updater

Schema-based slug plugin for Mongoose - single/compound - unique over collection/group - nested docs/arrays - relative/abs paths - sync on change: create/save/update/updateOne/updateMany/findOneAndUpdate tracked - $set operator - counter/shortId
MIT License
40 stars 13 forks source link

Problem with NestJS #34

Open watch-janick opened 4 months ago

watch-janick commented 4 months ago

Hello!

Did anyone already used this plugin successfully with NestJS?

I'm following NestJS Mongoose documentation to add the plugin to my schema but it doesn't work.

In my module:

@Module({
  imports: [
    MongooseModule.forFeatureAsync([
      {
        name: Passage.name,
        useFactory: () => {
          const schema = PassageSchema
          schema.plugin(require('mongoose-slug-updater'))
          return schema
        },
      },
    ]),
  ],
  controllers: [PassageController],
  providers: [PassageService],
})
export class PassageModule {}

In my schema:

@Prop({
  // required: true,
  unique: true,
  slug: ['field1', 'field2', 'field3'],
})
slug: string

Every time I create an instance of it, it doesn't add the slug at all to the database and on the second occurrence I run into a duplicate error, so it looks like the plugin doesn't have any effect.

Anyone figured it out?