title: Mongoose Model - Updating an Array
body: <pre><code>{ _id: 55c02ab7684c7a601ca24898,
    title: 'this is a better poll',
    link: 'this-is-a-better-poll',
    creator: 'user',
    __v: 0,
    choices:
     [ { text: 'Option 1', votes: 0 },
       { text: 'Option 2', votes: 0 } ] }
  </code></pre>
  
  <p>This is an example of a poll. Let's say I have multiple of these in my database.</p>
  
  <p>I need to update the <strong><em>number of votes</em></strong> per POST request by the client by comparing the <strong><em>Option</em></strong> being posted to the server and comparing it to the database.</p>
  
  <p>Since there are multiple polls in the database, I am using the <strong><em>link</em></strong> to find the exact database object.</p>
  
  <p>I tried multiple ways to <em>update the votes count</em>, but nothing seems to work, changing the title works flawlessly though. Why?</p>
  
  <p>Method that failed: </p>
  
  <pre><code>for example selection is: 
  var selection = 'Option 1';
  var link = 'this-is-a-better-poll';
  
  1) Model.where({"choices.text": selection}).update({$set: {"choices.votes" : 1}});
  
  2) Model.update({"choices.text": selection}, {'$set': {"choices.$.votes" : 1}});
  
  3)     Model.findOne({
          link: link
      }, function(err, found) {
          if (err) {
              return res.status(400).send({
                  message: 'Error'
              });
          }
          if (found) {
              console.log(found.choices);
              var arr = found.choices;
              for (var i = 0; i &lt; arr.length; i++) {
                  if (arr[i].text == selection) {
                      arr[i].votes = 1
                      console.log(arr[i].votes = 1);
                  }
                  found.save(function(err) {
                      if (err) res.send(err);
                      res.status(200).send({
                          message: 'Succes'
                      });
                  });
              }
  
          }
      });
  </code></pre>
  
  <p>How can I solve this problem? How can I update the vote count when the selection is made? </p>