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
I have searched existing issues to ensure the bug has not already been reported
Mongoose version
8.9.1, 8.7.3
Node.js version
18.16.0
MongoDB server version
4.8.1
Typescript version (if applicable)
No response
Description
Defining more than one discriminated schema causes an Error: Discriminator with name already exists
Steps to Reproduce
'use strict';constmongoose=require('mongoose');const{ Schema }=mongoose;constbaseSchema=newSchema({type: {type: Number,required: true},},{discriminatorKey: "type"});constselfRefSchema=newSchema({self: {type: [baseSchema]},});constanotherSelfRefSchema=newSchema({self2: {type: [baseSchema]},});baseSchema.discriminator(5,selfRefSchema);baseSchema.discriminator(6,anotherSelfRefSchema);// Commenting this line make the script workmongoose.model("base",baseSchema);// Error: Discriminator with name "5" already exists
Expected Behavior
Should be able to define any number of schemas that self reference.
The text was updated successfully, but these errors were encountered:
Prerequisites
Mongoose version
8.9.1, 8.7.3
Node.js version
18.16.0
MongoDB server version
4.8.1
Typescript version (if applicable)
No response
Description
Defining more than one discriminated schema causes an
Error: Discriminator with name already exists
Steps to Reproduce
Expected Behavior
Should be able to define any number of schemas that self reference.
The text was updated successfully, but these errors were encountered: