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

237
Vistas
Moongose: update record pushing element into array

Sorry for my poor english, I hope you understand what I mean.

I have a mongoDb database with many tables. In my table "Files" all the records has a field called "etiquetas". This field is an array of strings. I want to update this field (in a the record with id XXXX) inserting new strings. I have read the docs of mongoose and I have tried to update a record using "push" function, but mongoose its inserting an object and not a string into the array "etiquetas".

Let me show you whats is happening. This is whats Im doing to update the record (in a nodejs app):

let exampleString = "61c43b346c6168d039f8c0gg"; // Using an example string
await File.updateOne(
  { id: fileId },
  { $push: { etiquetas: { exampleString } } }
);

And this is what is happening (I have inserted manually the first record of the array "etiquetas"):

click to see what it happens

over 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try to remove the curly braces surrounding the exampleString:

let exampleString = "61c43b346c6168d039f8c0gg"; // Using an example string
await File.updateOne(
  { id: fileId },
  { $push: { etiquetas: exampleString } }
);
over 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
Asistente virtual