From 4d41004eaee0b639b173639b5c5d2338bcfcb61c Mon Sep 17 00:00:00 2001 From: Kristina Chodorow Date: Thu, 5 Nov 2009 21:58:21 +0000 Subject: [PATCH] safe insert git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@290361 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/mongo/mongocollection/insert.xml | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/reference/mongo/mongocollection/insert.xml b/reference/mongo/mongocollection/insert.xml index 6d24b227f5..6a3c2b148c 100644 --- a/reference/mongo/mongocollection/insert.xml +++ b/reference/mongo/mongocollection/insert.xml @@ -53,6 +53,13 @@ + + &reftitle.errors; + + Throws MongoCursorException if safe is set and the insert fails. (Version 1.0.1+) + + + &reftitle.examples; @@ -93,6 +100,34 @@ array(1) { ]]> + + + <function>MongoCollection::insert</function> safe example + + This example shows inserting two elements with the same _id, which causes + a MongoCursorException to be thrown, as + safe was set. + + + "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"; +} + +?> +]]> + +