我在 NestJs 库中使用 Mongoose,并希望对我的所有模式都使用 mongoose -delete插件。
但我不知道如何将它与 nestJS 和 Typescript 一起使用。
首先我安装了两个库mongoose-delete
,@Types/mongoose-delete
但是这个插件没有打字稿纪录片。这是通过嵌套添加插件的推荐方法:
MongooseModule.forRoot(MONGO_URI, {
connectionFactory: connection => {
connection.plugin(require('mongoose-delete'));
return connection;
},
}),
这绝对会产生 esLint 错误:
要求语句不是导入语句的一部分。eslint
而且我不能使用delete
功能。它没有在 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 -^
}