title: Remove a MongoDB Document by ObjectId with PHP
body: <p>I'm new to both PHP and MongoDB.  I'd like to remove a MongoDB document using it's ObjectId, but can't seem to get it working.</p>
  
  <p>Here is how the object gets added.  Because I do not specify the id, Mongo generates one for me.</p>
  
  <pre><code>public static function addUserPet($userPet) {
      $m = new MongoClient();
      $db = $m-&gt;petfinder;
      $collection = $db-&gt;userpets;
      $collection-&gt;insert($userPet);
      echo json_encode($userPet);
  }
  </code></pre>
  
  <p>And here is where I attempt to update the object.  I don't understand how to access the document using the ObjectId.</p>
  
  <pre><code>public static function deleteUserPet($userPet)
  {
      $m = new MongoClient();
      $db = $m-&gt;petfinder;
      $collection = $db-&gt;userpets;
  
      $criteria = ???
  
      $collection-&gt;remove($criteria, true);
  }
  </code></pre>
  
  <p>What should $criteria be?</p>
  
  <p>Note:  Here is the object being passed in.
  <a href="https://i.stack.imgur.com/yiFRh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yiFRh.png" alt="$userPet"></a></p>