📌  相关文章
📜  以编程方式更改猫鼬模式枚举值 - 无论代码示例

📅  最后修改于: 2022-03-11 14:58:02.582000             🧑  作者: Mango

代码示例1
//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 });
}