Ejemplo n.º 1
0
 public function updateWithErrors()
 {
     $bulk = new MongoDB\Driver\BulkWrite(['ordered' => false]);
     //limit: limit the number of documents matched and updated to the specified value or unlimited when 0
     //You can also use something like ["viking" => "false"] for the first (filter) line
     //        $bulk->update(
     //            ["_id" => ['$in' => ["1001", "1002"]]],
     //            ['$inc' => ["days.01.views" => 1]],
     //            ["limit" => 0, "upsert" => false, "multi" => true]
     //        );
     $bulk->update(["_id" => "1001"], ['$inc' => ["days.01.views" => 1]], ["limit" => 0, "upsert" => false, "multi" => false]);
     $bulk->update(["_id" => "1002"], ['$inc' => ["days.01.views" => 1]], ["limit" => 0, "upsert" => false, "multi" => false]);
     $bulk->update(["_id" => "1500"], ['$inc' => ["days.01.views" => 1]], ["limit" => 0, "upsert" => false, "multi" => false]);
     $bulk->update(["_id" => "2001"], ['$inc' => ["days.01.views" => 1]], ["limit" => 0, "upsert" => false, "multi" => false]);
     echo "roundtrips: " . $bulk->count() . "\n";
     try {
         $result = $this->mongo_manager->executeBulkWrite($this->databaseAndCollectionName(), $bulk, $this->write_concern);
         var_dump($result);
         //echo "\ngetinfo():\n|";
         //echo $result->getInfo();
         //echo "|\n\n";
     } catch (MongoDB\Driver\Exception\Exception $e) {
         echo "catch: mongo error:\n";
         echo $e->getMessage(), "\n";
     }
 }