title: Mongoose Nodejs pull element from array by property of property
body: <p>So here is my mongoose Object:</p>
  <pre><code>{ 
      &quot;_id&quot; : ObjectId(&quot;626aaff13fa90efda9ea1975&quot;), 
      &quot;username&quot; : &quot;Raxo&quot;, 
      &quot;password&quot; : &quot;089a9902261aa3d27218ef8ea5e4885a52cafc7278684978b0953dc6846f07a6&quot;, 
      &quot;solved&quot; : [ 
      { 
          &quot;challenge&quot; : { 
              &quot;_id&quot; : ObjectId(&quot;627178fd7fff3bdc2ad941e6&quot;), 
              &quot;name&quot; : &quot;Challenge6315 &quot;, 
              &quot;category&quot; : &quot;crypto&quot;, 
              &quot;flag&quot; : &quot;Nice try XD&quot;, 
              &quot;hints&quot; : [ &quot;Easy Peasy Lemon Squeezy!&quot; ], 
              &quot;points&quot; : 100, 
              &quot;info&quot; : &quot;I am a challenge!&quot;, 
              &quot;level&quot; : 0, &quot;solveCount&quot; : 0, 
              &quot;file&quot; : &quot;&quot;, 
              &quot;__v&quot; : 0 
          }, 
          &quot;timestamp&quot; : 1651603748444
      }], 
      &quot;score&quot; : 800, 
      &quot;key&quot; : &quot;65b8457a-9c00-4829-8d18-ed2e19cef53&quot;, 
      &quot;isAdmin&quot; : true, 
      &quot;teamId&quot; : &quot;62717c6a7b8c337ac509176a&quot;, 
      &quot;__v&quot; : 0 
  }
  </code></pre>
  <p>I am trying to delete the challenge inside the solved array using:</p>
  <pre><code>        await users.updateMany({
              solved: { $elemMatch: { 'challenge._id': challengeExists._id } }
          }, {
              $inc: { score: -challengeExists.points },
              $pull: {solved: {&quot;challenge._id&quot;: challengeExists._id}}
          });
  </code></pre>
  <p>It does find the user successfully and remove points from the score but does not successfully pull the challenge, I cant seem to find what I am doing wrong. Any help appreciated</p>
  <p>Also weirdly it works in the CLI with:</p>
  <pre><code>db.users.updateMany({ solved: { $elemMatch: { 'challenge._id': ObjectId(&quot;627191c0fcff360116a67528&quot;) } } }, { $pull: { solved: { &quot;challenge._id&quot;: ObjectId(&quot;627191c0fcff360116a67528&quot;) } }, $inc: { score: -100 }, })
  </code></pre>