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

Mongoose population type is wrong #2549

Open
1 of 5 tasks
MickL opened this issue Nov 24, 2022 · 1 comment
Open
1 of 5 tasks

Mongoose population type is wrong #2549

MickL opened this issue Nov 24, 2022 · 1 comment

Comments

@MickL
Copy link
Contributor

MickL commented Nov 24, 2022

I'm submitting a...

  • Regression
  • Bug report
  • Feature request
  • Documentation issue or request (new chapter/page)
  • Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

In docs of https://docs.nestjs.com/techniques/mongodb the population example is shown as the following:

@Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'Owner' })
owner: Owner;

But actually this is not correct, instead in reality owner is of type ObjectId. Only when explicitly populating the query owner ist of type Owner.

In the example the definition of CreateCatDto is not shown but if the types are used everywhere then the compiler would complain because there is a mismatch: When creating a new Cat one need to add owner of type ObjectId and not of type Owner as the compile would demand. Also when querying for Cat one will get an ObjectId while the compile thinks it is Owner.

Expected behavior

Provide a better example / best practice of population. Mongoose docs: https://mongoosejs.com/docs/typescript/populate.html

@AxelDavid45
Copy link
Contributor

Hi!
I want this improvement to be done as well, I'll send a PR because I think this is important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants