Skip to content

Mongoose population type is wrong #2549

Open
@MickL

Description

@MickL

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions