title: Uncaught exception 'MongoCursorException' with message .... duplicate key error index:
body: <p>Here's my code:</p>
  
  <p>When i try to work it, there's an error as it: </p>
  
  <pre><code> "Fatal error: Uncaught exception 'MongoCursorException' with message
   'localhost:27017: E11000 duplicate key error index: 
    futbol_db.maclar.$kod_1_link_1 dup key:
    { : null, : null }' in /var/www/html/cagkansokmen/futbol/db/maclar.php:182 
    Stack trace: #0 /var/www/html/cagkansokmen/futbol/db/maclar.php(182):    
    MongoCollection-&gt;insert(Array) #1 {main} thrown in 
    /var/www/html/cagkansokmen/futbol/db/maclar.php on line 182"
  </code></pre>
  
  <p>The problem is about insert. Because, when i drop insert code, there's no problem about this code. But if i try to insert data, there's an error just as i said.</p>
  
  <p>How can i fix it?</p>
  
  <pre><code>$collection1 = $db-&gt;lig_kod;
  $collection_maclar = $db-&gt;maclar;
      $collection1-&gt;ensureIndex(array("kod" =&gt; 1, "link" =&gt; 1), array("unique" =&gt; true, "dropDups" =&gt; true));
  
      $a = $collection1-&gt;find(array())-&gt;limit(15)-&gt;skip(0);
      foreach($a as $b){
      $kod = $b["kod"];
      $link = $b["link"];
  
          $parc = explode(',', $link);
          $ligkoduson = $parc[0].",".$parc[1];
      $url2 = "http://www.stats.betradar.com/s4/gismo.php?&amp;html=1&amp;id=1424&amp;language=tr&amp;clientid=35&amp;state=".$ligkoduson.",5_".$kod.",9_fixtures,231_fixtures,23_1,242_21&amp;child=0";
          $url2 = curl($url2);
          $url2 = str_replace("\t","",$url2);
          $url2 = str_replace("\n","",$url2);
          $url2 = str_replace("\r","",$url2);
  
          $bul = ara("&lt;![CDATA[", "]]&gt;", $url2);
          $sonuc = ara("setState('", ",", $bul[0]);
          $say = count($sonuc);
  
          for($i = 0; $i&lt;$say; $i++){
          $sezonbul = $sonuc[$i];
  
          $lonk = "http://www.stats.betradar.com/s4/gismo.php?&amp;html=1&amp;id=2127&amp;language=tr&amp;clientid=35&amp;state=".$ligkoduson.",".$sezonbul.",9_fixtures,231_full,23_1&amp;child=2";
          $fiksturlink = curl("http://www.stats.betradar.com/s4/gismo.php?&amp;html=1&amp;id=2127&amp;language=tr&amp;clientid=35&amp;state=".$ligkoduson.",".$sezonbul.",9_fixtures,231_full,23_1&amp;child=2");
  
          $fiksturlink = str_replace("\t","",$fiksturlink);
          $fiksturlink = str_replace("\n","",$fiksturlink);
          $fiksturlink = str_replace("\r","",$fiksturlink);
  
          $kategori = ara('title="', '"', $fiksturlink);
          $kategori_parcala = explode(' &amp;gt; ', $kategori[0]);
          $tur = trim($kategori_parcala[0]);
          $ulke = trim($kategori_parcala[1]);
              $lig = $kategori_parcala[2];
              $lig_parcala = explode(' ', $lig);
              $lig_bosluk = count($lig_parcala)-1;
          $sezon = trim($lig_parcala[$lig_bosluk]);
          $lig_son = trim(str_replace($sezon, "", $lig));
  
  
              $takimlar = ara('&lt;span class="teams"&gt;', '&lt;/a&gt;', $fiksturlink);
              $timebul = ara('&lt;td class="datetime"&gt;', '&lt;/td&gt;', $fiksturlink);
              $fhbul = ara('&lt;td class="p1 "&gt;', '&lt;/td&gt;', $fiksturlink);
              $ftbul = ara('&lt;td class="nt ftx "&gt;', '&lt;/td&gt;', $fiksturlink);
              $dongusay = count($takimlar);
          echo $dongusay."&lt;br&gt;";
          for($dongu = 0; $dongu&lt;$dongusay; $dongu++){
              $takimlarbul = ara('"&gt;', '&lt;/span&gt;', $takimlar[$dongu]);
  
              $home = trim($takimlarbul[0]);
              $away = trim($takimlarbul[2]);
                  $time = trim($timebul[$dongu]);
                  $time_ayir = explode(' ', $time);
                  $yil_ayir = explode('/', $time_ayir[0]);
                      $gun = $yil_ayir[0];
                      $ay = $yil_ayir[1];
                      $yil = $yil_ayir[2];
                  $saat_ayir = explode(':', $time_ayir[1]);
                      $saat = $saat_ayir[0];
                      $dk = $saat_ayir[1];
              $time_sonuc = mktime($saat, $dk, 0, $ay, $gun, $yil);
              $fh = trim($fhbul[$dongu]);
                  if(empty($fh)){
                  $fh1 = null;
                  $fh2 = null;
                  }else{
                  $fh_ayir = explode(':', $fh);
                  $fh1 = $fh_ayir[0];
                  $fh2 = $fh_ayir[1];
                  }
              $ft = trim($ftbul[$dongu]);
              if(empty($ft)){
  
                  $ft1 = null;
                  $ft2 = null;
  
              }else{
                  if(strpos($ft, '(')){
  
                      $parcala1 = explode('(', $ft);
                      $ft_ayir = explode(':', $parcala1[0]);
                      $ft1 = $ft_ayir[0];
                      $ft2 = $ft_ayir[1];
  
                  }else{
  
                      $ft_ayir = explode(':', $ft);
                      $ft1 = $ft_ayir[0];
                      $ft2 = $ft_ayir[1];
                  }
              }
          echo $ligkoduson."-".$sezonbul."-".$tur."-".$ulke."-".$lig_son."-".$sezon."-".$home."-".$away."-".$time_sonuc."-".$fh1."-".$fh2."-".$ft1."-".$ft2."&lt;br&gt;";
  
          $collection_maclar-&gt;insert(array(
          'ulke_kodu'=&gt;$ligkoduson,
          'sezon_kodu'=&gt;$sezonbul,
          'tur'=&gt;$tur,
          'ulke'=&gt;$ulke,
          'lig'=&gt;$lig_son,
          'sezon'=&gt;$sezon,
          'home'=&gt;$home,
          'away'=&gt;$away,
          'tarih'=&gt;$time_sonuc,
          'fh1'=&gt;$fh1,
          'fh2'=&gt;$fh2,
          'ft1'=&gt;$ft1,
          'ft2'=&gt;$ft2
          ));
          }
          }
  
          }
  </code></pre>