title: Removing undefined from MongoDB array
body: <p>I have added undefined values to array using script performed on a server side (Mongo version - 3.4.10).</p>
  
  <p>Let's say I have document like</p>
  
  <pre><code>{
     "array" : ["a","b", undefined]
  }
  </code></pre>
  
  <p>and I want to remove undefined element.</p>
  
  <p>When I query it like this</p>
  
  <pre><code>find({"array" :  {$elemMatch : {$in : [null], $exists : true} }})
  </code></pre>
  
  <p>It returns above document - Mongo treats null and undefined as equal.</p>
  
  <p>However, below update query is not removing element as expected (works fine for nulls)</p>
  
  <pre><code>update({} ,{ $pull : {"array" : {$in : [null]} }}, {multi : true})
  </code></pre>
  
  <p>It is also not possible to use undefined as math expression</p>
  
  <pre><code>InMatchExpression equality cannot be undefined
  </code></pre>
  
  <p><strong>Question:</strong> How do you remove elements in such a situation?</p>