I need to indicate which user made the last modification of the document in MongoDB.
I have the following Categories model:
import { Schema, model } from "mongoose";
const CategorySchema = Schema (
{
name: {
type: String,
maxlength:50,
unique: true,
required: [true, 'El Nombre es obligatorio']
},
desc: {
type: String,
maxlength:50,
required: [true, 'El Apellido es obligatorio']
},
img: {
type: String
},
status: {
type: Boolean,
default: true,
required: [true, 'El Estatus es obligatorio']
},
user:{
type: Schema.Types.ObjectId,
ref:'Users',
required: [true, 'El Usuario es obligatorio']
},
createdAt: {
type: Date,
default: Date.now
}
}
);
My idea is to get the _id of the user who is doing the update and insert it into another object in the model and also another object that gets the update date. Something like:
lastModificationBy:{
type: String,
maxlength:50,
required: true
},
updatedAt:{
type: Date,
default: Date.now
}
However, I do not know if this is correct and functional. Thanks for your help.