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 6.4.X breaks PopulatedDoc parent-child relation typing, circular reference itself, works with 6.3.9. #12136

Closed
2 tasks done
SteadEXE opened this issue Jul 22, 2022 · 1 comment
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@SteadEXE
Copy link

SteadEXE commented Jul 22, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

6.4.9

Node.js version

16.15.1

MongoDB server version

5.0.3

Description

After upgrading from 6.3.9 to 6.4.6 my schemas are broken.
I am using Nest Framework, but it's only decorators (see snippet below).

I tried to use the documentation but the documentation code is broken.
https://mongoosejs.com/docs/typescript/populate.html#using-populateddoc
ObjectId comes from nowhere, so the code can't run since ObjectId does not exist.

I tried everything I could without knowing what do to.
At the moment I downgraded to 6.3.9 and it works.
I am using TypeScript 4.7.4.

image

image

Steps to Reproduce

import { Prop, Schema } from "@nestjs/mongoose";  // Can safely be removed
import { Document, PopulatedDoc, SchemaTypes } from "mongoose";

export type ChildDocument = Child & Document;
export type ParentDocument = Parent & Document;

@Schema()  // Can safely be removed
export class Child {
  @Prop({ type: SchemaTypes.ObjectId, ref: 'Parent' })  // Can safely be removed
  parent: PopulatedDoc<ParentDocument>;
}

@Schema()  // Can safely be removed
export class Parent {
  @Prop({ type: SchemaTypes.ObjectId, ref: 'Child' })  // Can safely be removed
  child: PopulatedDoc<ChildDocument>;
}

Expected Behavior

I expect the code to run just fine.
There are lot of reason to use bi-directional relation in order.
I don't expect parent.child and child.parent to be populated at the same time anyway.

@IslandRhythms IslandRhythms added the typescript Types or Types-test related issue / Pull Request label Jul 22, 2022
@vkarpov15 vkarpov15 added this to the 6.4.8 milestone Jul 25, 2022
@vkarpov15
Copy link
Collaborator

Looks like this issue was introduced in v6.4.1 with #11911. Fix will be in v6.5.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

No branches or pull requests

3 participants