title: How to first check the array in mongodb and then add item if it does not already contain this item(string)?
body: <p>Here is my code till now:</p>
  <pre><code>Scorecard.findOneAndUpdate(
      { _id: fielderRoleInfo.player_id },
      { $push: { [&quot;score.&quot; + n + &quot;.catches&quot;]: dismissedPlayer } },
      function (err, docs) {
        if (err) {
          console.log(err);
        } else {
          // console.log(&quot;Updated Fielder : &quot;, docs);
  
        }
      }
    );
  </code></pre>
  <p>dismissedPlayer and fielderRoleInfo are defined somewhere else in code. This code add duplicate strings(dismissedPlayer) in catches array inside the object in score array( score is an array of objects). I want to first check if string(dismissedPlayer) exist in array and if it not exist, then only add in array. Note: dismissedPlayer is a variable and it will have dynamic values</p>