Alterar programaticamente os valores do esquema de mangusto
//My field is called "status" inside my schema. So "validate" will check if can pass or not.
status: { type: String, default: 'Abierta', validate: (v) => {
return customEnum(v, 'Status');
}},
// And this is my "customEnum" module
// This is the collection where I store the data. I don't want to use only, status, so
// I made it dynamic, to choose what I want to retrieve.
const SingleValue = require('../models/SingleValue');
module.exports = async (v, type) => {
return !!await SingleValue.findOne({ typeOf: type, deleted: false, value: v });
}
Courageous Chicken