MorphiaOrg / MorphiaOrg/morphia

Allow to disable the Discriminators by default

Open
#1,463 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement proposed
Dominant language
Java
Stars
1.7k
Forks
449
Avg merge
7m
Merged PRs (30d)
10

Description

Is your feature request related to a problem?
I don't see the need to store discriminators by default, it just adds more data to the document, so it has an impact on the IO + storage. The only use case I see for this feature, is when we have to deal with polymorphism, which is not required for every project.

Describe the solution you'd like
In the MapperOptions.Builder, we can already configure the discriminator key & discriminator function, why not also include a method enableDiscrimitatorByDefault(boolean). This way we could easily override this value only when there's some polymorphism involve in the class we are designing.

Describe alternatives you've considered
No

Additional context
I'm not an MongoDB expert, so I don't know if the discriminator feature is use for other things, would this have a performance impact?! (I doubt) Unfortunately, the documentation I found was not very clear about what a discriminator was used for, so I would also recommend to include a brief explanation here:
https://morphia.dev/2.0.0/guides/configuration/#discriminator-keys-and-values
In google, I found more information about the discriminator in the csharp driver page:
https://mongodb.github.io/mongo-csharp-driver/2.0/reference/bson/mapping/polymorphism/
I understand this is a common feature in Mongo no matter which language we are using on the client side, but it would be nice to still explain not only the how, but the why of the discriminator within Morphia.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with MapperOptions.Builder and the discriminator configuration described in the Morphia configuration guide. Determine how the default discriminator behavior is configured and review the linked documentation context for its purpose. Done means the requested default-setting option is supported and the guide explains both how and why discriminators are used.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mongodb
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.