From b56bee1a3159a2dc48e4ca37436ae99925656e2e Mon Sep 17 00:00:00 2001 From: Kristina Chodorow Date: Thu, 19 Nov 2009 21:09:52 +0000 Subject: [PATCH] update parameters, cursor description git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@291033 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/mongo/book.xml | 15 +--- reference/mongo/mongocollection/update.xml | 81 +++++++++++++++++++++- reference/mongo/mongocursor.xml | 22 +++++- 3 files changed, 101 insertions(+), 17 deletions(-) diff --git a/reference/mongo/book.xml b/reference/mongo/book.xml index 50555ccee7..980f1d251d 100644 --- a/reference/mongo/book.xml +++ b/reference/mongo/book.xml @@ -7,23 +7,14 @@ &reftitle.intro; - - These functions allow PHP to interact with Mongo database servers. - - MongoDB is a high-performance, open source, schema-free document database - designed for cloud computing. The project's goal is a cloud-scale data store - that's easy to deploy, manage and use. It's network accessible and written in - C++. + designed for creating scalable websites. - More information and downloads for Mongo can be found at &url.mongodb;. - - - - There are also tutorials at &url.mongodb.php;. + More information and downloads for Mongo can be found at &url.mongodb; and + information about PHP in particular at &url.mongodb.php;. diff --git a/reference/mongo/mongocollection/update.xml b/reference/mongo/mongocollection/update.xml index 451df90d87..c69263afb2 100644 --- a/reference/mongo/mongocollection/update.xml +++ b/reference/mongo/mongocollection/update.xml @@ -13,7 +13,7 @@ public booleanMongoCollection::update arraycriteria arraynewobj - booleanupsert&false; + arrayoptions&null; @@ -43,11 +43,32 @@ - upsert + options - If $newobj should be inserted if the criteria is not found. + This parameter is an associative array of the form + array("optionname" => <boolean>, ...). Currently + supported options are: + + + + "upsert" + + + If no document matches $criteria, a new document will be created from + $criteria and $newobj (see upsert example below). + + + + + "multiple" + + + All documents matching $criteria will be updated. + + + @@ -97,6 +118,60 @@ array(4) { ]]> + + <function>MongoCollection::update</function> upsert example + + Upserts can simplify code, as a single line can create the object if it does + not exist yet and update it if it does. + + +drop(); +$c->update(array("uri" => "/summer_pics"), array("page hits" => array('$inc' => 1)), array("upsert" => true)); +var_dump($c->findOne()); + +?> +]]> + + &example.outputs.similar; + + + object(MongoId)#9 (0) { + } + ["uri"]=> + string(12) "/summer_pics" + ["page hits"]=> + int(1) +} +]]> + + + + <function>MongoCollection::update</function> multiple example + + By default, MongoCollection::update will only update + the first document matching $criteria that it finds. Using the "multiple" + option can override this behavior, if needed. + + + This example adds a "gift" field to every person whose birthday is in the + next day. + + + new MongoDate(), '$lt' => new MongoDate(strtotime("+1 day"))); +$people->update("birthday" => $today), array('$set' => array('gift' => $surprise), array("multiple" => true)); + +?> +]]> + +