2

类型被添加到 Mongoose 5.10.5 中,看起来它们与@types/mongoose. 然后我的代码不再运行:

import MongooseDeletePlugin from 'mongoose-delete';
...

@Module({
  imports: [
    MongooseModule.forRoot(MONGO_URI, {
      connectionFactory: (connection: Connection) => {
        connection.plugin(MongooseDeletePlugin, {

        // ^--- This generates error: "Property 'plugin' does not exist on type 'Connection'."

          overrideMethods: 'all',
          deletedAt: true,
          indexFields: ['deleted'],
        });
        return connection;
      },
    }),
...

在 Mongoose 文档中,是添加全局插件的正确方法。但是如何将它添加到 NestJS 中?

const mongoose = require('mongoose');
mongoose.plugin(require('./loadedAt'));
4

0 回答 0