You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constclickedEventSchema=newmongoose.Schema({element: String},{discriminatorKey: 'kind'});eventSchema.discriminator('ClickedEvent',clickedEventSchema,{value: 'click'});// ^ this will not be usedconstEvent=mongoose.model('Event',eventSchema);constdoc=awaitEvent.create({kind: 'clicked',element: '#hero'});doc.element;// '#hero'docinstanceofClickedModel;// this should be `true`, this will currently be `false`
constmongoose=require('mongoose');consteventSchema=newmongoose.Schema({name: String});constclickedEventSchema=newmongoose.Schema({element: String},{discriminatorKey: 'kind'});eventSchema.discriminator('ClickedEvent',clickedEventSchema,{value: 'click'});// ^ this will not be usedconstEvent=mongoose.model('Event',eventSchema);constClickedModel=mongoose.model('Clicked',clickedEventSchema);asyncfunctionrun(){awaitmongoose.connect('mongodb://localhost:27017');awaitmongoose.connection.dropDatabase();constdoc=awaitEvent.create({kind: 'clicked',element: '#hero'});doc.element;// '#hero'console.log(docinstanceofClickedModel);// this should be `true`, this will currently be `false`console.log('done');}run();
Prerequisites
Mongoose version
7.x.x, 8.x.x
Node.js version
20.x
MongoDB server version
7.2.2
Typescript version (if applicable)
No response
Description
While the
options
for a discriminator can be defined on aModel
,SchemaSubdocument
orSchemaDocumentArray
, they cannot be defined on a generalSchema
.Steps to Reproduce
Expected Behavior
Potential fix: master...forivall:mongoose:schema-discriminator-options
The text was updated successfully, but these errors were encountered: