php-doc-en/reference/mongo/mongowritebatch/execute.xml
Yannick Torres d5a500831e Fix svn keywords
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@333942 c90b9560-bf6c-de11-be94-00142212c4b1
2014-06-25 16:57:52 +00:00

261 lines
6.1 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="mongowritebatch.execute" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoWriteBatch::execute</refname>
<refpurpose>Description</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>final</modifier> <modifier>public</modifier> <type>array</type><methodname>MongoWriteBatch::execute</methodname>
<methodparam><type>array</type><parameter>write_options</parameter></methodparam>
</methodsynopsis>
<para>
Executes the MongoWriteBath.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>write_options</parameter></term>
<listitem>
<para>
See <link linkend="mongowritebatch.construct.write_options">MongoWriteBatch::__construct</link>.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
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.
</para>
<para>
If the batch was empty, an array containing only the 'ok' field is returned (as &true;) although
nothing will be shipped over the wire (<acronym>NOOP</acronym>).
</para>
<para>
<informaltable>
<thead>
<row>
<entry>Array key</entry>
<entry>Value meaning</entry>
<entry>Returned for batch type</entry>
</row>
</thead>
<tbody>
<row>
<entry>nInserted</entry>
<entry>Number of inserted documents</entry>
<entry>MongoWriteBatch::COMMAND_INSERT batch</entry>
</row>
<row>
<entry>nMatched</entry>
<entry>Number of documents matching the query criteria</entry>
<entry>MongoWriteBatch::COMMAND_UPDATE batch</entry>
</row>
<row>
<entry>nModified</entry>
<entry>Number of documents actually needed to be modied</entry>
<entry>MongoWriteBatch::COMMAND_UPDATE batch</entry>
</row>
<row>
<entry>nUpserted</entry>
<entry>Number of upserted documents</entry>
<entry>MongoWriteBatch::COMMAND_UPDATE batch</entry>
</row>
<row>
<entry>nRemoved</entry>
<entry>Number of documents removed</entry>
<entry>MongoWriteBatch::COMMAND_DELETE batch</entry>
</row>
<row>
<entry>ok</entry>
<entry>Command success indicator</entry>
<entry>All</entry>
</row>
</tbody>
</informaltable>
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
A <classname>MongoWriteConcernException</classname> exception is thrown on failure.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example xml:id="mongowritebatch.execute.example.insert">
<title><methodname>MongoWriteBatch::add</methodname> example</title>
<para>
Batching up multiple insert operations
</para>
<programlisting role="php">
<![CDATA[
<?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);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
array(2) {
["nInserted"]=>
int(3)
["ok"]=>
bool(true)
}
]]>
</screen>
</example>
<example xml:id="mongowritebatch.execute.example.update">
<title><methodname>MongoWriteBatch::add</methodname> example</title>
<para>
Batching up multiple update operations
</para>
<programlisting role="php">
<![CDATA[
<?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);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
array(4) {
["nMatched"]=>
int(18)
["nModified"]=>
int(2)
["nUpserted"]=>
int(0)
["ok"]=>
bool(true)
}
]]>
</screen>
</example>
<example xml:id="mongowritebatch.execute.example.delete">
<title><methodname>MongoWriteBatch::add</methodname> example</title>
<para>
Batching up multiple delete operations
</para>
<programlisting role="php">
<![CDATA[
<?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);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
array(2) {
["nRemoved"]=>
int(1)
["ok"]=>
bool(true)
}
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->