diff --git a/reference/mongo/mongocollection/update.xml b/reference/mongo/mongocollection/update.xml
index 01fc958f53..b07c1d5932 100644
--- a/reference/mongo/mongocollection/update.xml
+++ b/reference/mongo/mongocollection/update.xml
@@ -57,8 +57,16 @@
If no document matches $criteria, a new
- document will be created from $criteria and
- $new_object (see upsert example below).
+ document will be inserted.
+
+
+ If a new document would be inserted and
+ $new_object contains atomic modifiers
+ (i.e. $ operators), those operations will be
+ applied to the $criteria parameter to create
+ the new document. If $new_object does not
+ contain atomic modifiers, it will be used as-is for the inserted
+ document. See the upsert examples below for more information.
@@ -270,17 +278,28 @@ array(4) {
- MongoCollection::update upsert example
+ MongoCollection::update upsert examples
- Upserts can simplify code, as a single line can create the object if it does
- not exist yet and update it if it does.
+ Upserts can simplify code, as a single line can create the document if it
+ does not exist (based on $criteria), or update an
+ existing document if it matches.
+
+
+ In the following example, $new_object contains an
+ atomic modifier. Since the collection is empty and upsert must insert a new
+ document, it will apply those operations to the
+ $criteria parameter in order to create the document.
drop();
-$c->update(array("uri" => "/summer_pics"), array('$inc' => array("page hits" => 1)), array("upsert" => true));
+$c->update(
+ array("uri" => "/summer_pics"),
+ array('$inc' => array("page hits" => 1)),
+ array("upsert" => true)
+);
var_dump($c->findOne());
?>
@@ -301,9 +320,10 @@ array(3) {
]]>
- If $new_object does not contain $-operators, an upsert will
- create a new document from the passed fields only. This matches the
- behavior of a normal update, where not using $-operators causes the whole
+ If $new_object does not contain atomic modifiers
+ (i.e. $ operators), upsert will use
+ $new_object as-is for the new document. This matches
+ the behavior of a normal update, where not using atomic modifiers causes the
document to be overwritten.