nestjs/mongoose

Cannot populate using a dynamic ref inside an array of embedded discriminators

Opened this issue · 1 comments

kiyui commented

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Dynamic ref functions do not appear to work in @nestjs/mongoose. The ref function appears to be resolved at the time the schema is created, instead of at runtime.

This has been reported in the past here: #1847

This makes resolving the type for an array of embedded discriminators difficult in deeply nested or dynamic data structures where refPath may not be suitable.

Minimum reproduction code

https://github.com/kiyui/nestjs-mongoose-ref-issue-reproduction

Steps to reproduce

See the proof of work section in the reproduction repository.

Expected behavior

The schema should not resolve a ref function's return at the time of its creation, but allow them to be run at runtime so the behaviour is the same as that of Mongoose.

The reproduction repository shows the difference of behaviour between this module and plain Mongoose and asserts this with integration tests for the two.

Package version

10.0.6

mongoose version

8.4.4

NestJS version

10.3.10

Node.js version

18.20.3, 20.15.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Following.... 👀

@kiyui was asked to report his issue from the Discord forum.

Scott