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

91
Visualizações
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 à 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