最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to use `mongoose

网站源码admin36浏览0评论

How to use `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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论