question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error is thrown when base model's schema specifies options that are not reflected in discriminator model's schema

See original GitHub issue

When using the new discriminator models, mongoose throws an error, if the base model’s schema specifies schema options that are not reflected in the discriminator model’s schema.

Here is a simple code snippet that shows the issue:

var BaseSchema = new mongoose.Schema({
    "name": String
}, {
    "versionKey": false
});

var DiscriminatorSchema = new mongoose.Schema({
    "something": String
});

var Base = mongoose.model("Base", BaseSchema);
var Discriminator = Base.discriminator("Discriminator", DiscriminatorSchema);

The following error is thrown:

Error: Discriminator options are not customizable (except toJSON & toObject)

I understand that you can’t set schema options on a schema used in a discriminator model, but it should not be an issue the other way around. I would expect the schema options of the base schema to be “inherited” by the discriminator schema.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:6
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
vkarpov15commented, Jun 16, 2017

@ksloan this particular issue is fixed. If you’re experiencing a similar issue, please open up a new issue with a repro script.

1reaction
ksloancommented, Jun 14, 2017

Was this never fixed? Seeing this in 4.10.6.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mongoose discriminators and required/unique fields
It is logical that error would be thrown since Author introduced required field that Moderator does not have. How is that handled?
Read more >
Mongoose v6.8.2: Schemas
Each schema maps to a MongoDB collection and defines the shape of the documents within ... To do so, we pass it into...
Read more >
Schema generation rules · GitBook - Goswagger.Io
For each schema, go-swagger will generate one or more model types in go. ... Generated models uses no reflection except for enum and...
Read more >
JSON Type Definition | Ajv JSON schema validator
JTD schema forms. JTD specification defines 8 different forms that the schema for JSON can take for one of most widely used data...
Read more >
OpenAPI CodeGen Extensions - APIMatic Documentation
These settings will be globally applicable to all operations and schema ... the SDK will not throw an exception but instead pass the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found