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

88
Vistas
Trying to update values in an array in mongodb

MongoDB Structure

Hi everyone,

I'm trying to update a document in my mongodb. I try this by the code down below. With the code I am everytime updating the first data in the array called 'Kassen'. My goal in this question is to know how I can define that I want to update for example the second or third dataset of the 'Kassen' array. I want to use the variable called 'kasnumber' to define which dataset I want from the array. What you can see in the image I've got the same problem with the array called 'afdelingen' but I think it will work the same way.

router.patch('/:postId',async (req, res) => {
try{
    let kasnumber = parseInt(req.body.user.kasnumber);

const updatedPost = await Post.updateOne(
    {Gebruikersnaam: req.params.postId}, 
    {$set:  {
        FirstName: req.body.user.FirstName,
        bedrijf:{
            Kassen: [{                                 
                KasId: req.body.user.KasId,
                Name: req.body.user.KasName,                                   
                },
        PassWord: req.body.user.PassWord
            }
    }
);
console.log(updatedPost);
res.json(updatedPost);
}
catch(err) {
    res.json({message: err})
}

});

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