<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->

<refentry xml:id="mongodb-driver-bulkwrite.update" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
 <refnamediv>
  <refname>MongoDB\Driver\BulkWrite::update</refname>
  <refpurpose>Add an update operation to the bulk</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <modifier>public</modifier> <type>void</type><methodname>MongoDB\Driver\BulkWrite::update</methodname>
   <methodparam><type class="union"><type>array</type><type>object</type></type><parameter>filter</parameter></methodparam>
   <methodparam><type class="union"><type>array</type><type>object</type></type><parameter>newObj</parameter></methodparam>
   <methodparam choice="opt"><type class="union"><type>array</type><type>null</type></type><parameter>updateOptions</parameter><initializer>&null;</initializer></methodparam>
  </methodsynopsis>
  <para>
   Adds an update operation to the
   <classname>MongoDB\Driver\BulkWrite</classname>.
  </para>

 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <variablelist>
   &mongodb.parameter.filter;
   <varlistentry>
    <term><parameter>newObj</parameter> (<type class="union"><type>array</type><type>object</type></type>)</term>
    <listitem>
     <para>
      A document containing either update operators (e.g.
      <literal>$set</literal>), a replacement document (i.e.
      <emphasis>only</emphasis> <literal>field:value</literal> expressions), or
      an <link xlink:href="&url.mongodb.docs.command;update/#update-with-an-aggregation-pipeline">aggregation pipeline</link>.
     </para>
    </listitem>
   </varlistentry>
   <varlistentry>
    <term><parameter>updateOptions</parameter></term>
    <listitem>
     <para>
      <table>
       <title>updateOptions</title>
       <tgroup cols="4">
        <thead>
         <row>
          <entry>Option</entry>
          <entry>Type</entry>
          <entry>Description</entry>
          <entry>Default</entry>
         </row>
        </thead>
        <tbody>
         <row>
          <entry>arrayFilters</entry>
          <entry><type>array</type></entry>
          <entry>
           <para>
            An array of filter documents that determines which array elements to
            modify for an update operation on an array field. See
            <link xlink:href="&url.mongodb.docs.command;update/#update-command-arrayfilters">Specify arrayFilters for Array Update Operations</link>
            in the MongoDB manual for more information.
           </para>
           <para>
            This option is available in MongoDB 3.6+ and will result in an
            exception at execution time if specified for an older server
            version.
           </para>
          </entry>
         </row>
         &mongodb.option.collation;
         <row>
          <entry>hint</entry>
          <entry><type class="union"><type>string</type><type>array</type><type>object</type></type></entry>
          <entry>
           <para>
            Index specification. Specify either the index name as a string or
            the index key pattern. If specified, then the query system will only
            consider plans using the hinted index.
           </para>
           <para>
            This option is available in MongoDB 4.2+ and will result in an
            exception at execution time if specified for an older server
            version.
           </para>
          </entry>
         </row>
         <row>
          <entry>multi</entry>
          <entry><type>bool</type></entry>
          <entry>
           Update only the first matching document if &false;, or all
           matching documents &true;. This option cannot be &true; if
           <parameter>newObj</parameter> is a replacement document.
          </entry>
          <entry>&false;</entry>
         </row>
         <row>
          <entry>upsert</entry>
          <entry><type>bool</type></entry>
          <entry>
           If <parameter>filter</parameter> does not match an existing document,
           insert a <emphasis>single</emphasis> document. The document will be
           created from <parameter>newObj</parameter> if it is a replacement
           document (i.e. no update operators); otherwise, the operators in
           <parameter>newObj</parameter> will be applied to
           <parameter>filter</parameter> to create the new document.
          </entry>
          <entry>&false;</entry>
         </row>
        </tbody>
       </tgroup>
      </table>
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   &return.void;
  </para>
 </refsect1>

 <refsect1 role="errors">
  &reftitle.errors;
  <simplelist>
   &mongodb.throws.argumentparsing;
  </simplelist>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <para>
   <informaltable>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>&Version;</entry>
       <entry>&Description;</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>PECL mongodb 1.7.0</entry>
       <entry>
        Added the <literal>"hint"</literal> option.
       </entry>
      </row>
      <row>
       <entry>PECL mongodb 1.6.0</entry>
       <entry>
        The <parameter>newObj</parameter> parameter now accepts an aggregation
        pipeline. This feature requires MongoDB 4.2+ and will result in an
        exception at execution time if specified for an older server version.
       </entry>
      </row>
      <row>
       <entry>PECL mongodb 1.5.0</entry>
       <entry>
        Using the <literal>"arrayFilters"</literal> option will result in an
        exception at execution time if unsupported by the server. Previously,
        no exception would be thrown and the option may have been ignored.
       </entry>
      </row>
      <row>
       <entry>PECL mongodb 1.4.0</entry>
       <entry>
        Added the <literal>"arrayFilters"</literal> option.
       </entry>
      </row>
      <row>
       <entry>PECL mongodb 1.2.0</entry>
       <entry>
        Added the <literal>"collation"</literal> option.
       </entry>
      </row>
     </tbody>
    </tgroup>
   </informaltable>
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <example>
   <title><function>MongoDB\Driver\BulkWrite::update</function> example</title>
   <programlisting role="php">
<![CDATA[
<?php

$bulk = new MongoDB\Driver\BulkWrite;
$bulk->update(
    ['x' => 2],
    ['$set' => ['y' => 3]],
    ['multi' => false, 'upsert' => false]
);

$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017');
$result = $manager->executeBulkWrite('db.collection', $bulk);

?>
]]>
   </programlisting>
  </example>
 </refsect1>


 <refsect1 role="seealso">
  &reftitle.seealso;
  <simplelist>
   <member><methodname>MongoDB\Driver\Manager::executeBulkWrite</methodname></member>
   <member><classname>MongoDB\Driver\WriteResult</classname></member>
  </simplelist>
 </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
-->
