title: PHP MongoDb insert deletes all old record
body: <p>I am inserting multiple records from a csv file into mongodb. </p>
  
  <p>The records are inserted but whenever I am running the script, all the <strong>previous records gets deleted</strong> and only the new records are left</p>
  
  <pre><code>$connection=  new \MongoClient();
  $db = $connection-&gt;selectDB('mydb');
  $collection =  $db-&gt;selectCollection('users');
  
  while (($data = fgetcsv($file, 0, ",")) !==FALSE) {
   try{ 
          $userData['_id'] =  new \MongoId();
          $userData['name'] = $data['0'];
          $userData['email'] = $data['1'];
          $userData['extra_info'] = $data['2'];
  
  
          $collection-&gt;insert($userData);
      }catch(MongoCursorException $e){
          // This is where I caught the duplicate id
          print_r($e-&gt;doc['err']);
  
          // Kill the procedure
          die();
      }
  }
  </code></pre>