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

128
Visualizações
mongoose.findByIdAndUpdate will only save the first key-value of object being pushed into array

I have a simple object that stores two values inside, each being a req.body value from data sent from client.

const pushedVote = {
      answer: req.body.answer, 
      text: req.body.value
    }

Now, when I call the findByIdAndUpdate method it looks like this (with Poll being my model)

//insert answer and text 
    await Poll.findByIdAndUpdate(req.body.id, {
      $push: {
        responseAnswers: pushedVote,
      },
    });

This all works fine, but what's weird is that the array in my database that is updated will ONLY store the first key-value pair in the object. For example, if the pushedVote object that is being stored had answer as 'A' and text as 'Cat', the database will only store 'A', and not 'Cat' along with it. Am I missing something here?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As per my comment, make sure that the text property is defined in the Mongoose schema, otherwise it won't be saved to the database.

about 4 years ago · Juan Pablo Isaza Relatório
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