Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rossohin opened this issue Nov 23, 2022 · 0 comments
Open

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

rossohin opened this issue Nov 23, 2022 · 0 comments
Labels
bug A feature or code that is not working properly

Comments

@rossohin
Copy link

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)
@rossohin rossohin added the bug A feature or code that is not working properly label Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A feature or code that is not working properly
Projects
None yet
Development

No branches or pull requests

1 participant