title: Error 'Cannot apply $pull to a non-array value'
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>db.collection(USERDETAILS_COLLECTION).findOneAndUpdate({
      "emailVerificationHistory.verifyCode": mailCode
    }, {
      '$pull': {
        "emailVerificationHistory.$.verifyCode": mailCode
      }
    },
    function(err, pullData) {
      if (err) {
        console.log(err);
      } else {
        res.send({
          msg: 'User Verified Succesfully',
          status: 1
        });
      }
    });</code></pre>
  </div>
  </div>
  </p>
  <p>When I execute the above code, I am getting the following error.</p>
  <pre><code>name: 'MongoError',
    message: 'Cannot apply $pull to a non-array value',
    ok: 0,
    errmsg: 'Cannot apply $pull to a non-array value',
    code: 16837,
  </code></pre>
  <p>Below is my MongoDB object.</p>
  <pre><code>{
      &quot;_id&quot; : ObjectId(&quot;593270b8bc98ea235cfaf68f&quot;),
      &quot;username&quot; : &quot;parengalhisham@gmail.com&quot;,
      &quot;roleId&quot; : 3,
      &quot;userId&quot; : ObjectId(&quot;593270b8bc98ea235cfaf68e&quot;),
      &quot;profile&quot; : {
          &quot;firstName&quot; : &quot;Hisham&quot;,
          &quot;lastName&quot; : &quot;Mubarak&quot;
      },
      &quot;activeFlag&quot; : 1,
      &quot;authType&quot; : [ 
          &quot;facebook&quot;
      ],
      &quot;emailVerified&quot; : false,
      &quot;emailVerificationHistory&quot; : [ 
          {
              &quot;email&quot; : &quot;parengalhisham@gmail.com&quot;,
              &quot;verifyCode&quot; : &quot;59327155480b791b7845dfd7&quot;,
              &quot;requestDate&quot; : ISODate(&quot;2017-06-03T08:20:37.156Z&quot;),
              &quot;verifiedDate&quot; : ISODate(&quot;2017-06-03T10:31:53.720Z&quot;)
          }
      ]
  }
  </code></pre>
  <p>How do I search through the emailVerificationHistory array using verifyCode and remove the verifyCode only from that first object inside array? Thank you for your help in advance.</p>