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

178
Visualizações
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 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

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