title: Uncaught MongoDB\Driver\Exception\InvalidArgumentException: Error parsing ObjectId string:
body: <p>I was trying to create a project using MongoDB and PHP .
  I created a table and inserted all data .
  Now I want to delete the record using delete button and I inserted delete link in each row.
  I linked it to delete.php which contains following code.</p>
  <pre><code>&lt;?php 
  require 'vendor/autoload.php';
  $id = $_GET['id']; 
  $conn=new MongoDB\Client(&quot;mongodb://localhost:27017&quot;);
  $db=$conn-&gt;project;
  $collection=$db-&gt;notes;
  
  try{
  $id =new  MongoDB\BSON\ObjectID($id);
  $collection-&gt;deleteOne(array('_id'=&gt;$id ));
  header('location:real.php');
  }
  catch(Expection $e){}
  ?&gt;
  </code></pre>
  <p>But now I am getting this error</p>
  <pre><code>Uncaught MongoDB\Driver\Exception\InvalidArgumentException: Error parsing ObjectId string: in C:\xampp\htdocs\mongo\delete.php:9 Stack trace: #0 C:\xampp\htdocs\mongo\delete.php(9): MongoDB\BSON\ObjectId-&gt;__construct('') #1 {main} thrown in C:\xampp\htdocs\mongo\delete.php on line 9
  </code></pre>
  <p>My index.php contains following code</p>
  <pre><code>&lt;div method=&quot;post&quot;&gt;
  
          &lt;table style=&quot;width:50%&quot; border=&quot;solid&quot;&gt;
            &lt;tr&gt;
              &lt;th&gt;_id&lt;/th&gt;
              &lt;th&gt;Author&lt;/th&gt;
              &lt;th&gt;Subject&lt;/th&gt;
              &lt;th&gt;Title&lt;/th&gt;
              &lt;th&gt;Notes&lt;/th&gt;
              &lt;th&gt;Difficulty&lt;/th&gt;
              &lt;th&gt;Related Topics&lt;/th&gt;
              &lt;th&gt;Action&lt;/th&gt;
            &lt;/tr&gt;
  
          &lt;?php
          
          $collection = $db-&gt;notes;
          $data = $collection-&gt;find();
          foreach($data as $document){
           ?&gt; 
              &lt;tr&gt;
              &lt;td&gt;&lt;?php echo $document['_id'] ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $document['author'] ?&gt;&lt;/td&gt; 
              &lt;td&gt;&lt;?php echo $document[&quot;subject&quot;] ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $document[&quot;title&quot;] ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $document[&quot;notes&quot;] ?&gt;&lt;/td&gt; 
              &lt;td&gt;&lt;?php echo $document[&quot;difficulty&quot;] ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $document[&quot;rel_topic&quot;] ?&gt;&lt;/td&gt; 
              &lt;td&gt;&lt;a href='delete.php?id=&lt;?php $document['_id'];?&gt;'&gt;Delete&lt;/a&gt;&lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
          
      &lt;/div&gt;      
  </code></pre>
  <p>Please Help me!! I am new to PHP</p>