How to use `mongoose

编程入门 行业动态 更新时间:2024-10-07 09:20:05

How to use `<a href=https://www.elefans.com/category/jswz/34/1771443.html style=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

本文发布于:2024-05-30 09:47:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770364.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:mongoose

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!