I'm using Mongoose in NestJs library and want to use mongoose-delete plugin for all of my schemas.
But I don't know how to use it with nestJS And Typescript.
First i installed both mongoose-delete
and @Types/mongoose-delete
libraries but there is no typescript documentary for This plugin.
This is the recommended method for adding plugin by nest:
MongooseModule.forRoot(MONGO_URI, {
connectionFactory: connection => {
connection.plugin(require('mongoose-delete'));
return connection;
},
}),
And absolutely this generates esLint error:
Require statement not part of import statement.eslint
And I cannot use delete
function. It's not defined in the mongoose.Dcoument
export type ChannelDocument = Channel & Document;
constructor(
@InjectModel(Channel.name) private _channelModel: Model<ChannelDocument>,
) {}
async delete(id: string) {
this._channelModel.delete({ id });
// This is undefined -^
}