Search code examples
inheritancemongooseschemadiscriminator

Mongoose change name of discriminator key


I would like to change the schema inheritance discriminator key. This documentation says, it is __t 'by default', however I can find no way to change the key, e.g. to type.

Is there any configuration available?


Solution

  • Must have overlooked this. Example from the top of the mentioned documentation page:

    var options = {discriminatorKey: 'kind'};
    
    var eventSchema = new mongoose.Schema({time: Date}, options);
    var Event = mongoose.model('Event', eventSchema);