Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
Register the last user who made modifications to the document in MongoDB

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!