svn: /phpdoc/en/trunk/reference/mongo/mongocollection/ insert.xml

From: Date: Thu, 05 Nov 2009 21:58:21 +0000
Subject: svn: /phpdoc/en/trunk/reference/mongo/mongocollection/ insert.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-5278@lists.php.net to get a copy of this message
kristina Thu, 05 Nov 2009 21:58:21 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=290361 Log: safe insert Changed paths: U phpdoc/en/trunk/reference/mongo/mongocollection/insert.xml Modified: phpdoc/en/trunk/reference/mongo/mongocollection/insert.xml =================================================================== --- phpdoc/en/trunk/reference/mongo/mongocollection/insert.xml 2009-11-05 19:11:06 UTC (rev 290360) +++ phpdoc/en/trunk/reference/mongo/mongocollection/insert.xml 2009-11-05 21:58:21 UTC (rev 290361) @@ -53,6 +53,13 @@ </para> </refsect1> + <refsect1 role="errors"> + &reftitle.errors; + <para> + Throws MongoCursorException if <parameter>safe</parameter> is set and the insert fails. (Version 1.0.1+) + </para> + </refsect1> + <refsect1 role="examples"> &reftitle.examples; <example> @@ -93,6 +100,34 @@ ]]> </screen> </example> + + <example> + <title><function>MongoCollection::insert</function> safe example</title> + <para> + This example shows inserting two elements with the same _id, which causes + a <classname>MongoCursorException</classname> to be thrown, as + <parameter>safe</parameter> was set. + </para> + <programlisting role="php"> +<![CDATA[ +<?php + +$person = array("name" => "Joe", "age" => 20); +$collection->insert($person, true); + +// now $person has an _id field, so if we save it +// again, we will get an exception +try { + $collection->insert($person, true); +} +catch(MongoCursorException $e) { + echo "Can't save the same person twice!\n"; +} + +?> +]]> + </programlisting> + </example> </refsect1> </refentry>

« previous php.doc.cvs (#5278) next »