php-doc-en/reference/mongo/functions/mongo-update.xml
2009-02-25 22:50:52 +00:00

159 lines
3.8 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.3 $ -->
<refentry xml:id="function.mongo-update" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>mongo_update</refname>
<refpurpose>Updates objects in a database collection</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>bool</type><methodname>mongo_update</methodname>
<methodparam><type>resource</type><parameter>connection</parameter></methodparam>
<methodparam><type>string</type><parameter>ns</parameter></methodparam>
<methodparam><type>array</type><parameter>query</parameter></methodparam>
<methodparam><type>array</type><parameter>newobj</parameter></methodparam>
<methodparam><type>bool</type><parameter>upsert</parameter></methodparam>
</methodsynopsis>
<para>
Removes matching objects, changes them to match a new object form, and
resaves them to the database. If there are no matching objects and
upsert is set, the new object will be inserted into the database.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>connection</parameter></term>
<listitem>
<para>
The database connection to use.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>ns</parameter></term>
<listitem>
<para>
The database and collection name
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>query</parameter></term>
<listitem>
<para>
The object for which to query.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>newobj</parameter></term>
<listitem>
<para>
The object to replace matches with.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>upsert</parameter></term>
<listitem>
<para>
Whether to insert newobj into the collection
if no objects are returned by the query.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
If the update was successful.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
When does this function issue E_* level errors, and/or throw exceptions.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>mongo_update</function> example</title>
<para>
This example shows how to update an existing object.
</para>
<programlisting role="php">
<![CDATA[
<?php
$query = array("x" => "y");
$newobj = array("x" => "z");
$conn = mongo_connect("localhost", true);
if (!$conn) {
die("Could not connect.");
}
$ok = mongo_update($conn, "foo.bar", $query, $newobj, false);
if( $ok ) {
echo "updated";
}
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
updated
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>mongo_insert</function></member>
<member><function>mongo_remove</function></member>
</simplelist>
</para>
</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:"../../../../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
-->