При наличии следующего кода:
const schema = new Schema({
_id: {
type: String
},
name: {
type: String,
required: true,
trim: true
}
}
schema.pre('validate', (next) => {
console.log(this.name);
this._id = crypto.createHash('md5').update(this.name).digest("hex");
next();
});
const myObject = new MyObject({ name: 'SomeName' });
myObject.save();
Приложение выдает это сообщение об ошибке:
MongooseError: document must have an _id before saving
Мой вопрос: как можно вручную установить _id для модели?
И почему это имя не определено