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
The docs say it is possible to use three parameters to Model.discriminator(). If the third one is specified, it is used as a value for the discriminator. However the generated index in MongoDB uses the first parameter (the model name).
Consider the following example:
letBasePaymentSchema=newmongoose.Schema({amount: mongoose.Types.Decimal128},{discriminatorKey: 'provider'})letBasePayment=mongoose.model('Payment',BasePaymentSchema)letPaypalPaymentSchema=newmongoose.Schema({transactionId: {type: String,unique: true}})letPaypalPayment=BasePayment.discriminator('PaypalPayment',PaypalPaymentSchema,'paypal'// This value should be in discriminator field)
So basically the model name (PaypalPayment) is used as a partialFilterExpression instead of the supplied discriminator value (paypal). This way the unique constraint doesn't work at all.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node 11.12.0
Mongoose 5.4.19
MongoDB 4.0.6
The text was updated successfully, but these errors were encountered:
Do you want to request a feature or report a bug?
A bug.
What is the current behavior?
The docs say it is possible to use three parameters to Model.discriminator(). If the third one is specified, it is used as a value for the discriminator. However the generated index in MongoDB uses the first parameter (the model name).
Consider the following example:
But if I do
db.payments.getIndexes()
I get:So basically the model name (
PaypalPayment
) is used as apartialFilterExpression
instead of the supplied discriminator value (paypal
). This way theunique
constraint doesn't work at all.What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node 11.12.0
Mongoose 5.4.19
MongoDB 4.0.6
The text was updated successfully, but these errors were encountered: