mongoose"/>
How to use `mongoose
我在 NestJs 库中使用 Mongoose,并希望对我的所有模式使用 mongoose-delete 插件。
但我不知道如何将它与 nestJS 和 Typescript 一起使用。
首先我安装了
mongoose-delete
和 @Types/mongoose-delete
库,但是这个插件没有 typescript 文档。
这是推荐的嵌套添加插件的方法:
MongooseModule.forRoot(MONGO_URI, {
connectionFactory: connection => {
connection.plugin(require('mongoose-delete'));
return connection;
},
}),
这绝对会产生 esLint 错误:
Require 语句不是导入语句的一部分.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 -^
}
回答如下:
安装此包后尝试重新启动 IDE(如果使用 vscode):@types/mongoose-delete
更多推荐
How to use `mongoose
发布评论