Mongoose plugin registration not working
Josuto opened this issue · comments
We realize that the plugin uniqueValidator
is not executed:
import { SUPPORTED_LANGUAGES } from '@config/supported-languages';
import uniqueValidator from 'mongoose-unique-validator';
import { BaseSchema, extendSchema } from 'monguito';
export const SomeSchema = extendSchema(
BaseSchema,
{
title: Object.fromEntries(
SUPPORTED_LANGUAGES.map((langData) => [langData.id, { type: String, required: false }])
),
externalId: {
type: String,
required: true,
// This is not working
unique: true
},
},
{ timestamps: true }
);
// This is not working
SomeSchema.plugin(uniqueValidator);
When calling the save
function of Monguito it is saved even if the externalId
already exists. I do not know if it is a problem when using the extendSchema no longer allows plugins like mongoose-unique-validator
or if it is something else the problem. Any idea?
That's a bug 🐛. I will fix it by including a new property plugins
in the options
parameter of the extendSchema
utility function. This new property will enable monguito developers to specify an array of plugins they want to register in the schema resulting from the execution of the function. New release coming soon! 🎁