• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

129
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

about 3 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 } }
);
about 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda