title: How can I add to this schema array with mongoose?
body: <p>Here's the user schema and the part I want to update is ToDo under User.js (further down). I am attempting to add new data to an array within the db.</p>
  <p>data.js</p>
  <pre><code>app.post(&quot;/data&quot;, loggedIn, async (req, res) =&gt; {
    console.log(req.body.content);
    let content = { content: req.body.content };
    User.update({ _id: req.user._id }, { $set: req.body }, function (err, user) {
      if (err) console.log(err);
      if (!content) {
        req.flash(&quot;error&quot;, &quot;One or more fields are empty&quot;);
        return res.redirect(&quot;/&quot;);
      }
      user.ToDo.push(content);
      res.redirect(&quot;/main&quot;);
    });
  });
  </code></pre>
  <p>User.js</p>
  <pre><code>  new mongoose.Schema({
      email: String,
      passwordHash: String,
      ToDo: {
        type: [],
      },
      date: {
        type: Date,
        default: Date.now,
      },
    })
  </code></pre>
  <p>Originally I was trying the .push() attribute, but I get the error:</p>
  <blockquote>
  <pre><code>user.ToDo.push(content);
            ^
  </code></pre>
  <p>TypeError: Cannot read property 'push' of undefined</p>
  </blockquote>