nestjs/mongoose

occurred a dependency error after upgrade @nestjs/mongoose version(9.0.3 to 9.2.0)

Closed this issue · 3 comments

Did you read the migration guide?

  • I have read the whole migration guide

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Potential Commit/PR that introduced the regression

Versions

9.0.3 -> 9.2.0

Describe the regression

I tried to upgrade @nestjs/mongoose and mongoose(v6.6.5) for using MongoDB 6.0. but occurred an error when start the project.
The error comment in short, It can't inject a mongoose model into a repository.
but It works in @nestjs/mongoose(v9.0.3)

The error as below

`
Error: Nest can't resolve dependencies of the AdminUserRepository (?). Please make sure that the argument AdminUserModel at index [0] is available in the AdminUsersModule context.

Potential solutions:
- If AdminUserModel is a provider, is it part of the current AdminUsersModule?
- If AdminUserModel is exported from a separate @Module, is that module imported within AdminUsersModule?
  @Module({
    imports: [ /* the Module containing AdminUserModel */ ]
  })
`

Minimum reproduction code

repository code as below

`
@Injectable()
export class AdminUserRepository {
  constructor(@InjectModel(AdminUser.name) private readonly adminUserModel: SoftDeleteModel<AdminUserDocument>) {}
...
}
`

Expected behavior

It will be work after upgrade @nestjs/mongoose(9.2.0)

Other

I'm wondering why it does not work after upgrade @nestjs/mongoose(v9.2.0).

Did you read the migration guide?

  • I have read the whole migration guide

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Potential Commit/PR that introduced the regression

Versions

9.0.3 -> 9.2.0

Describe the regression

I tried to upgrade @nestjs/mongoose and mongoose(v6.6.5) for using MongoDB 6.0. but occurred an error when start the project. The error comment in short, It can't inject a mongoose model into a repository. but It works in @nestjs/mongoose(v9.0.3)

The error as below

`
Error: Nest can't resolve dependencies of the AdminUserRepository (?). Please make sure that the argument AdminUserModel at index [0] is available in the AdminUsersModule context.

Potential solutions:
- If AdminUserModel is a provider, is it part of the current AdminUsersModule?
- If AdminUserModel is exported from a separate @Module, is that module imported within AdminUsersModule?
  @Module({
    imports: [ /* the Module containing AdminUserModel */ ]
  })
`

Minimum reproduction code

repository code as below

`
@Injectable()
export class AdminUserRepository {
  constructor(@InjectModel(AdminUser.name) private readonly adminUserModel: SoftDeleteModel<AdminUserDocument>) {}
...
}
`

Expected behavior

It will be work after upgrade @nestjs/mongoose(9.2.0)

Other

I'm wondering why it does not work after upgrade @nestjs/mongoose(v9.2.0).

I'm in the same situation. After upgrading my version, all my models have stopped being injected.

Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).

I think this is related to @InjectModel if you're using a custom named connection.