title: MongoDB pull array element from a collection
body: <p>I have a mongodb object as follows:</p>
  
  <pre><code>array (
    '_id' =&gt; new MongoId("4cc97fb0247ae8747ec5fefb"),
    'posts' =&gt; 
    array (
      0 =&gt; 
      array (
        'comment' =&gt; 'Eamorr',
        'fromUname' =&gt; 'Eamorr',
        'time' =&gt; 1288273840,
        'UTC' =&gt; '2010-10-28T14:50:40+01:00',
        'ip' =&gt; '127.0.0.1',
        'id' =&gt; '123lasdfiqwoei28asdf',
      ),
      1 =&gt; 
      array (
        'comment' =&gt; 'Hello',
        'fromUname' =&gt; 'Eamorr',
        'time' =&gt; 1288277023,
        'UTC' =&gt; '2010-10-28T15:43:43+01:00',
        'ip' =&gt; '127.0.0.1',
        'id' =&gt; 'qopqwier982389qwfa',
      ),
      2 =&gt; 
      array (
        'comment' =&gt; 'Hello',
        'fromUname' =&gt; 'Anonymous',
        'time' =&gt; 1288283506,
        'UTC' =&gt; '2010-10-28T17:31:46+01:00',
        'ip' =&gt; '127.0.0.1',
        'id' =&gt; 'ioqwoeias892398wrf',
      ),
      /////
      //Want to remove element 3:
      /////
      3 =&gt; 
      array (
        'comment' =&gt; 'asdfasadf',
        'fromUname' =&gt; 'Anonymous',
        'time' =&gt; 1288283864,
        'UTC' =&gt; '2010-10-28T17:37:44+01:00',
        'ip' =&gt; '127.0.0.1',
        'id' =&gt; 'wwwwwiasdfn234oiasf',
      ),
      4 =&gt; 
      array (
        'comment' =&gt; 'asdfasdfasdf',
        'fromUname' =&gt; 'Anonymous',
        'time' =&gt; 1288284076,
        'UTC' =&gt; '2010-10-28T17:41:16+01:00',
        'ip' =&gt; '127.0.0.1',
        'id' =&gt; '290qwefoiqweproiqwerpq',
      ),
      5 =&gt; 
      array (
        'comment' =&gt; 'ASDF',
        'fromUname' =&gt; 'Eamorr',
        'time' =&gt; 1288284331,
        'UTC' =&gt; '2010-10-28T17:45:31+01:00',
        'ip' =&gt; '127.0.0.1',
        'id' =&gt; 'eioqw8923892hasdf',
      ),
      6 =&gt; 
      array (
        'comment' =&gt; 'ASDF2',
        'fromUname' =&gt; 'Eamorr',
        'time' =&gt; 1288284370,
        'UTC' =&gt; '2010-10-28T17:46:10+01:00',
        'ip' =&gt; '127.0.0.1',
        'id' =&gt; '23oaiofsaij234',
      ),
    ),
    'uname' =&gt; 'Eamorr',
  )
  </code></pre>
  
  <p>Now, I am writing some PHP code to remove posts[x]. I'm trying to use $pull to remove the array element.</p>
  
  <p>I have an 'id' 'wwwwwiasdfn234oiasf' (array element 3) and I want to remove this <em>entire</em> array element, leaving just 6 elements in the 'posts' array.</p>
  
  <p>I've tried googling and looking up the documentation to no avail... I still can't get the hang of the mongodb syntax.</p>
  
  <p>I'm doing all this in PHP, but any language will do I should be able to do the translation.</p>
  
  <p>Many thanks in advance,</p>
  
  <p>Solution (in PHP):</p>
  
  <pre><code>$uname=whatever
  $id=whatever
  $mongo=new Mongo();
  $walls=$mongo-&gt;people-&gt;walls;
  $walls-&gt;update(array('uname'=&gt;$uname),array('$pull'=&gt;array('posts'=&gt;array('id'=&gt;$id))));
  </code></pre>