Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

270
Vistas
How to merge two Mongoose Arrays inside Document in findByIdAndUpdate method Typescript Express

Have this model

export const IEventSchema = new mongoose.Schema<IEventBase>({
    type: {type: String, enum: EventType, required: true},
    date: {type: Number, required: true},
    title: {type: String},
    description: {type: String},
    notifiedUsers: [
        {
            type: Schema.Types.ObjectId,
            ref: 'User',
            default: {}
        }
    ],
    unnotifiedUsers: [
        {
            type: Schema.Types.ObjectId,
            ref: 'User',
            default: {}
        }
    ],
});

I want to move the contents of the notifiedUsers array to unnotifiedUsers, inside the findByIdAndUpdate method of the router.

router.put('/delay/:id', async (req: Request, res: Response) => {
    try {
        await Event.findByIdAndUpdate(req.params.id, {
                $set: {date: req.body.date},
                // Write Here
            }
        );
        res.status(200).json(`Event delayed to ${req.body.date}`);

    } catch (e: any) {
        console.log(e);
    }
});
$addToSet: {unnotifiedUsers: {$each: 'notifiedUsers'}} // Does not working
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda