title: How to remove array element in mongodb?
body: <p>Here is array structure</p>
  
  <pre><code>contact: {
      phone: [
          {
              number: "+1786543589455",
              place: "New Jersey",
              createdAt: ""
          }
          {
              number: "+1986543589455",
              place: "Houston",
              createdAt: ""
          }
  
      ]
  }
  </code></pre>
  
  <p>Here I only know the mongo id(<code>_id</code>) and phone number(<code>+1786543589455</code>) and I need to remove that whole corresponding array element from document. i.e zero indexed element in phone array is matched with phone number and need to remove the corresponding array element.</p>
  
  <pre><code>contact: {
      phone: [
          {
              number: "+1986543589455",
              place: "Houston",
              createdAt: ""
          }
      ]
  }
  </code></pre>
  
  <p>I tried with following update method</p>
  
  <pre><code>collection.update(
      { _id: id, 'contact.phone': '+1786543589455' },
      { $unset: { 'contact.phone.$.number': '+1786543589455'} }
  );
  </code></pre>
  
  <p>But it removes  <code>number:  +1786543589455</code> from inner array object, not zero indexed element in phone array. Tried with <code>pull</code> also without a success.</p>
  
  <p>How to remove the array element in mongodb?</p>