title: Mongodb odm docrine - self reference many to many (get specific data)
body: <p>I want to know how can I select specific friend from this model.<br>
  The model structure is here:</p>
  
  <pre class="lang-php prettyprint-override"><code>    /**
       * @MongoDB\ReferenceMany(targetDocument="Users", mappedBy="myFriends")
       */
      public $friendsWithMe;
  
      /**
       * @MongoDB\ReferenceMany(targetDocument="Users", inversedBy="friendsWithMe")
       */
      public $myFriends;
  
      public function __construct() {
          $this-&gt;friendsWithMe = new \Doctrine\Common\Collections\ArrayCollection();
          $this-&gt;myFriends = new \Doctrine\Common\Collections\ArrayCollection();
      }
  
      /**
       * Add friend
       * @param Users $user
       */
      public function addFriend(Users $user) {
          $user-&gt;friendsWithMe[] = $this;
          $this-&gt;myFriends[] = $user;
      }
  
      /**
       * Get friends
       * @return Array $myFriends
       */
      public function getFriends() {
          return $this-&gt;myFriends;
      }
  </code></pre>
  
  <p>To get user friends I use this code:</p>
  
  <pre><code>foreach($userSearch-&gt;getFriends() as $friend){
      $output .= "&amp;nbsp;FriendName: " . $friend-&gt;getFirstName() . " - ID: " . $friend-&gt;getId() . "&lt;br&gt;";
  }
  </code></pre>
  
  <p>So if I don't want to get all friend and loop over them how can I get specific users or user(friend/s) lets say older then 20 years.</p>
  
  <p><strong>EDITED</strong>
  Here im adding the document that is in the collection so im looking for a way to retrive one of the two friend with query for example who is older then x years instead of for loop on client side.</p>
  
  <pre><code>{
     "_id": ObjectId("503f3028e71a38840d000000"),
     "birthdate": ISODate("2012-08-30T09: 19: 36.0Z"),
     "email": "mail",
     "firstName": "asd",
     "myFriends": {
       "0": {
         "$ref": "Users",
         "$id": ObjectId("503e1683921da8c80b000002"),
         "$db": "testing" 
      },
       "1": {
         "$ref": "Users",
         "$id": ObjectId("503e0a8ee71a38080b000001"),
         "$db": "testing" 
      } 
    },
     "password": "123",
     "role": {
       "$ref": "UserRoles",
       "$id": ObjectId("50486ba1e71a384c15000000"),
       "$db": "testing" 
    },
     "username": "gizmo" 
  }
  </code></pre>
  
  <p><strong>Note:</strong> I'm using with module for ZF2 project (ZF2 + DoctrineOdmMongodb)</p>