I look around on how mongoDb change stream can be implemented in NestJs but so far, i can't find any solution or documentation.
There is a similar way by using Hooks middleware, but this can't be triggered if we change data from external app.
@Module({
imports: [
MongooseModule.forFeatureAsync([
{
name: Cat.name,
imports: [ConfigModule],
useFactory: (configService: ConfigService) => {
const schema = CatsSchema;
schema.post('save', function() {
console.log(
`${configService.get('APP_NAME')}: Hello from post save`,
),
});
return schema;
},
inject: [ConfigService],
},
]),
],
})
export class AppModule {}
I found this document https://www.mongodb.com/docs/manual/changeStreams/ but how can we implement this in NestJs?