title: How to push a value to an array using NodeJS and Mongoose
body: <p>I'm trying to update an array that is available on my MongoDB.
  I tried the way below but I reive the message &quot;Cannot read property push of undefined&quot;</p>
  <pre><code>router.get(&quot;/candidatarse/:id&quot;, eCandidato, (req,res)=&gt;{
  Vaga.findOne({_id: req.params.id}).then((vaga)=&gt;{
      
      vaga.candidatos.push(req.user._id)
  
      vaga.save().then(()=&gt;{
      req.flash(&quot;success_msg&quot;,&quot;Você se candidatou com sucesso! Continue encaminhando seu curriculo.&quot;)
      res.redirect(&quot;/&quot;)
  }).catch((err)=&gt;{
      req.flash(&quot;error_msg&quot;, &quot;Houve um erro ao cadastrar candidatura: &quot;+err)
      res.redirect(&quot;/&quot;)
  })
  })
  </code></pre>
  <p>})</p>
  <p>I also tried adding a position but didn't worked: <code>vaga.candidato[0].push(req.user.id)</code></p>
  <p>Here is how I have created the model:
  <a href="https://i.stack.imgur.com/ItsMf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ItsMf.png" alt="enter image description here" /></a></p>