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

136
Visualizações
Why didn't saving the mongoose work in this situation?

I have 2 cycles. The first one is for sorting posts. And the second one is to sort through the comments under these posts.

            Post.find().then(post =>{
              for(let i=0; i<post.length; i++){
                for(let ic=0; ic<post[i].comments.length; ic++){
                  if(post[i].comments[ic].user.secret_id == req.session.secret_id){
                    post[i].comments[ic].user.user_id = req.body.id;
                  }
                }
              }

              post.save()
               
            })

It's doesn't work

TypeError: post.save is not a function

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

0

It's because mongoose returns something called "mongoose object or mongo object" with additional metadata, not a plain javascript object when querying to database. So when you're performing "post[i].comments..." on the 5th line, it's modifying the mongoose object, you're trying to set a property which is calculated via for loop, but post isn't an array. There are this kind of typos, correct them and let's see what are the results.

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