Define discriminator at subSchema level direcly in subschema #7971
Labels
enhancement
This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Milestone
This is a feature request.
actually, following the documentation (and my research in the code),
you can do (taked from https://mongoosejs.com/docs/discriminators.html)
but if we change batchSchema to
now, you need to add both field to discriminator
this is event worse if "eventSchema" is used in many place, and have many discriminator, as you need to call all discriminator for each place eventSchema is used.
This would be far better if we could define discriminator direcly on eventSchema, as the discriminator would only be declared once for all schema who use "eventSchema".
from an api point of view, the best would be to be able to do
This api would also permit to create top-level schema-level discriminator.
This is not a breaking change, as it only add a possibility (a function to eventSchema), and do not have to break the other way of using discriminator. If used at the same time of other way, it can safely throw (as old code would not have this new function)
the capacity of using discriminator function at documentArray and Embedded level is still usefull, as it permit to not create a separate schema for embedded discrimination.
(As a side note, the documentation do not talk anywhere of the capacity of using discriminator on embedded subdocument in addition to documentArray. I had to check direcly in code to find it was possible)
version of program used :
mongoose : ^5.5.11
node : 11.7.0
mongodb : 4.0.0
The text was updated successfully, but these errors were encountered: