title: mongodb php findone() by ID
body: <p>This code will not find a record based on an ID search</p>
  
  <pre><code>&lt;?php
  
  $userid = $_GET['id'];
  
  $theObjId = new MongoId($userid); 
  
  $connection = new Mongo('localhost');
  
  $db = $connection-&gt;test-&gt;items; 
  
  $item = $db-&gt;findOne(array('_id' =&gt; $theObjId));
  
  echo 'Item: ' . $item . '&lt;br&gt;';
  
  echo 'UserID: ' . $userid . '&lt;br&gt;';
  
  echo 'TheObjID: ' . $theObjId;
  
  $connection-&gt;close(); 
  
  ?&gt;
  </code></pre>
  
  <p>$userid is supplied by a form in another .php file</p>
  
  <p>This is the output ....</p>
  
  <pre><code>$item: Array
  
   $userid: 4e0dfc8e7bfb8bac12000000
  
   $theObjId: 4e0dfc8e7bfb8bac12000000
  </code></pre>
  
  <p>the output proves my variables contain the ID</p>