title: mongo insert record if exist or update the record in mongo using php
body: <p>i am new to mongodb and i am trying to write a cron file which will fetch records from my mysql and store it in mongo collection. Now what i want is i need to write another code which will check the mongo collection if it has that record or not  .if not means it has to insert or else update the record</p>
  
  <p>my code is like this.</p>
  
  <pre><code> $query="select * from tt";
   $result=mysqli_query($connect,$query);
   while($fetch=mysqli_fetch_array($result)){
   $uname=$fetch['name'];
   $lastname=$fetch['lastname'];
   $surname=$fetch['surname'];
   $age=$fetch['age'];
  
  $document=array("name"=&gt;$uname,"lastname"=&gt;$lastname,"surname"=&gt;$surname,"age"=&gt;$age);
  </code></pre>
  
  <p>I want to check here whether the record is in mongo or not</p>
  
  <pre><code>$update = $collection-&gt;update($criteria,$document,array( 'upsert' =&gt;true));
  </code></pre>
  
  <p>I don't know what to give in the -criteria</p>