Skip to content

Type 'Db' is not assignable to type 'DbTypes | Promise<DbTypes>'. #529

@rossohin

Description

@rossohin

Describe the bug
After updating mongodb and mongoose packages, when I try to create new GridFsStorageInstance, this error appears:
Type 'Db' is not assignable to type 'DbTypes | Promise<DbTypes>'.

The full class is:

import { Injectable } from '@nestjs/common';
import { InjectConnection } from '@nestjs/mongoose';
import {
  MulterModuleOptions,
  MulterOptionsFactory,
} from '@nestjs/platform-express';
import { Connection } from 'mongoose';
import { GridFsStorage } from 'multer-gridfs-storage/lib/gridfs';

@Injectable()
export class GridFsMulterConfigService implements MulterOptionsFactory {
  private gridFsStorage: GridFsStorage;

  public constructor(@InjectConnection() private connection: Connection) {
    this.gridFsStorage = new GridFsStorage({
      db: this.connection.db,         // Type 'Db' is not assignable to type 'DbTypes | Promise<DbTypes>
      file: async (_, file) => {
        return new Promise(async (resolve) => {
          const filename = file.originalname.trim();
          const fileInfo = {
            filename,
          };

          resolve(fileInfo);
        });
      },
    });
  }

  public createMulterOptions(): MulterModuleOptions {
    return {
      storage: this.gridFsStorage,
    };
  }
}

Environment

  • I'm using multer-gridfs-storage version 5.0.2

  • My installed MongoDb version is 4.12.0

  • I have Multer 1.4.5-lts.1 installed to upload files

  • The Node version used to run the code is 16.16.0

  • I'm (using/not using) Mongoose connection objects to create storage instances. The Mongoose version installed is (major.minor.patch)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA feature or code that is not working properly

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions