Geen cache-versie.


Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

Rechercher une fonction PHP

MongoWriteBatch::execute

(PECL mongo >= 1.5.0)

MongoWriteBatch::executeExecutes a batch of write operations

Description

final public MongoWriteBatch::execute ( array $write_options ) : array

Executes the batch of write operations.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Return Values

Returns an array containing statistical information for the full batch. If the batch had to be split into multiple batches, the return value will aggregate the values from individual batches and return only the totals.

If the batch was empty, an array containing only the 'ok' field is returned (as TRUE) although nothing will be shipped over the wire (NOOP).

Array key Value meaning Returned for batch type
nInserted Number of inserted documents MongoWriteBatch::COMMAND_INSERT batch
nMatched Number of documents matching the query criteria MongoWriteBatch::COMMAND_UPDATE batch
nModified Number of documents actually needed to be modied MongoWriteBatch::COMMAND_UPDATE batch
nUpserted Number of upserted documents MongoWriteBatch::COMMAND_UPDATE batch
nRemoved Number of documents removed MongoWriteBatch::COMMAND_DELETE batch
ok Command success indicator All

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Errors/Exceptions

A MongoWriteConcernException exception is thrown on failure.

Eerste pagina van Manuel PHP  Inhoudsopgave Haut

Examples

Example #1 MongoWriteBatch::add() example

Batching up multiple insert operations

<?php
$mc 
= new MongoClient("localhost");
$collection $mc->selectCollection("test""test");


$docs = array();
$docs[] = array("my" => "demo");
$docs[] = array("is" => "working");
$docs[] = array("pretty" => "well");

$batch = new MongoInsertBatch($collection);
foreach(
$docs as $document) {
    
$batch->add($document);
}
$retval $batch->execute(array("w" => 1));
var_dump($retval);
?>

The above example will output:

array(2) {
  ["nInserted"]=>
  int(3)
  ["ok"]=>
  bool(true)
}

Example #2 MongoWriteBatch::add() example

Batching up multiple update operations

<?php
$mc 
= new MongoClient("localhost");
$collection $mc->selectCollection("test""test");


$item1 = array(
    
"q" => array("my" => "demo"),
    
"u" => array('$set' => array("try" => 1)),
    
"multi"  => false/* default value */
    
"upsert" => false/* default value */
);
$item2 = array(
    
"q" => array("is" => "working"),
    
"u" => array('$set' => array("try" => 2)),
    
"multi" => true,
);
$item3 = array(
    
"q" => array("created" => "new-document"),
    
"u" => array('$set' => array("try" => 3)),
    
"upsert" => true,
);

$batch = new MongoUpdateBatch($collection);
$batch->add($item1);
$batch->add($item2);
$batch->add($item3);
$retval $batch->execute(array("w" => 1));
var_dump($retval);

?>

The above example will output:

array(4) {
  ["nMatched"]=>
  int(18)
  ["nModified"]=>
  int(2)
  ["nUpserted"]=>
  int(0)
  ["ok"]=>
  bool(true)
}

Example #3 MongoWriteBatch::add() example

Batching up multiple delete operations

<?php
$mc 
= new MongoClient("localhost");
$collection $mc->selectCollection("test""test");


$item1 = array(
    
"q" => array("my" => "demo"),
    
"limit" => 1,
);
$item2 = array(
    
"q" => array("try" => 3),
    
"limit" => 1,
);


$batch = new MongoDeleteBatch($collection);
$batch->add($item1);
$batch->add($item2);
$retval $batch->execute(array("w" => 1));
var_dump($retval);
?>

The above example will output:

array(2) {
  ["nRemoved"]=>
  int(1)
  ["ok"]=>
  bool(true)
}
Zoek een PHP-functie

Vertaling niet beschikbaar

De PHP-handleiding is nog niet in het Nederlands vertaald, dus het scherm is in het Engels. Als u wilt, kunt u het ook in het Frans of in het Duits raadplegen.

Als je de moed voelt, kun je je vertaling aanbieden ;-)

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 30/01/2003 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/php-rf-mongowritebatch.execute.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:fr Manuel PHP : http://php.net

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut