Types are added to Mongoose 5.10.5 and it seems they are different from @types/mongoose
. Then my code is not running anymore:
import MongooseDeletePlugin from 'mongoose-delete';
...
@Module({
imports: [
MongooseModule.forRoot(MONGO_URI, {
connectionFactory: (connection: Connection) => {
connection.plugin(MongooseDeletePlugin, {
// ^--- This generates error: "Property 'plugin' does not exist on type 'Connection'."
overrideMethods: 'all',
deletedAt: true,
indexFields: ['deleted'],
});
return connection;
},
}),
...
In Mongoose documentations, this is the correct way to add a global plugin. But How can I add it to the NestJS?
const mongoose = require('mongoose');
mongoose.plugin(require('./loadedAt'));