Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

[Question] Problems reusing the same schema for both collection and subdocument #407

Closed
rubenvereecken opened this issue Jun 16, 2020 · 1 comment
Labels

Comments

@rubenvereecken
Copy link

Please see Automattic/mongoose#9128.

In short: I'm reusing a single schema for both a collection and as a subdocument. Indexes behave funny when I do so, because the collection's indexes are also used for the other collection where the collection's entries are subdocuments. I want to get rid of the indexes in the latter. This problem is a result of my database denormalisation.

There is a very helpful suggestion in that thread (the 1st one), which includes cloning the schema and setting off autoIndex on the copy. This is relatively elegant. So question numero uno -- is this possible in typegoose, somehow? Typegoose schemas are classes. I don't think I can copy them.

If the first question doesn't work out, I'd like to ask how to approach this differently? I can think of the following. Make on index-less class Event. Use that for subdocuments. Then extend this class with an class IndexedEvent extends Event that does have all the @index operators. Use this for the database collection. I think this would work. Just should refer to both by the super-class Event for interoperability. So never have a DocumentType<IndexedEvent>.

What do you think, @hasezoey? And again, much obliged for putting up with my questions.

@hasezoey
Copy link
Contributor

this repository is not maintained anymore, look at the new repository

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

No branches or pull requests

2 participants