Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda