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

212
Visualizações
How to insert an Array in Node js and MongoDB

Well, I am stuck since a long time on how to treat properly an array in Node js in order to persist it in my mongobd database. I tried a lot of stuff, i am feeling close to success, but still stuck with it with the var filmDataSchema and the var film syntax.

I really need a little help, please:

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

0

Are you using mongoose? it's an elegant mongodb object modeling for node.js and has a really nice interface to handle arrays so let's say you have a student model with grades array and you want to add a new grade, you can use the '$push' (if) or $addToSet operators like so

StudentModel.update(
   { _id: student._id }, 
   { $addToSet: { grades: grade } }
);

StudentModel.update(
   { _id: student._id }, 
   { $push: { grades: grade } }
);

use $addToSet if you want only unique items to be pushed into array. use $push if you just want to add the object to array whether or not the object is already there

more about mongoose can be found here https://mongoosejs.com/

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