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

126
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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