Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Is there a way to create a nested path instead of a subdocument? #611

Closed
eric-swann-q2 opened this issue Sep 17, 2021 · 1 comment
Closed
Labels
question Qustions about how to use stuff

Comments

@eric-swann-q2
Copy link

Is it possible to create a nested path as opposed to a subdocument and have tracking etc.. function?

In my case, I'm converting complex nested schemas to Typegoose, but am being forced to change what were previously basic nested paths into many separate nested subdocuments. I would be OK with this, but there are behavioral differences of subdocuments versus nested path in mongoose (I'm sure you know this already). It looks like Typegoose requires all nested entities to be subdocuments.

The main behavioral difference is that that a nested path is inherently lean, while a nested document comes with it's own wrapper and tracking, which is unnecessary in the vast majority of cases and messes up a lot of existing document parsing logic that we have in place on our project.

On the flip side, if I create a basic nested path inside of the parent, it doesn't track property changes with Typegoose.

Is there a way to force a nested entity to be a simple nested path and still function properly with Typegoose?

If not, is this something you would consider adding as a custom decorator?

Thanks,

Versions

I am running 8.3.0 on NodeJS 14 with Typescript 4.4.3. Mongoose is 5.13.8.

@eric-swann-q2 eric-swann-q2 added the question Qustions about how to use stuff label Sep 17, 2021
@eric-swann-q2 eric-swann-q2 changed the title Is there a way to create a subdocument without creating a separate schema? Is there a way to create a nested path instead of a subdocument? Sep 17, 2021
@hasezoey
Copy link
Member

yes there is a way in typegoose, called the Passthrough class, though it is not recommended to be used, when otherwise possible

also starting with mongoose 6.0.0 (and so typegoose 9.0.0), both ways should be equal (see Automattic/mongoose#7181)

@typegoose typegoose locked and limited conversation to collaborators Sep 17, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Qustions about how to use stuff
Projects
None yet
Development

No branches or pull requests

2 participants