From d35b3508e740b25aeb74b7f42270a9d0d6541741 Mon Sep 17 00:00:00 2001 From: Kristina Chodorow Date: Tue, 15 Dec 2009 14:34:15 +0000 Subject: [PATCH] added getters git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@292172 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/mongo/examples.xml | 4 +- reference/mongo/mongo/get.xml | 87 +++++++++++++++++++ .../mongo/mongocollection/batchinsert.xml | 2 +- .../mongo/mongocollection/createdbref.xml | 4 +- .../mongo/mongocollection/deleteindex.xml | 2 +- reference/mongo/mongocollection/get.xml | 76 ++++++++++++++++ reference/mongo/mongocollection/getdbref.xml | 2 +- reference/mongo/mongocollection/getname.xml | 2 +- reference/mongo/mongocollection/remove.xml | 2 +- reference/mongo/mongocollection/tostring.xml | 8 +- reference/mongo/mongocursor/tailable.xml | 11 ++- reference/mongo/mongodb/get.xml | 76 ++++++++++++++++ reference/mongo/mongodbref.xml | 4 +- reference/mongo/mongodbref/create.xml | 4 +- reference/mongo/tutorial.xml | 19 ++-- 15 files changed, 276 insertions(+), 27 deletions(-) create mode 100644 reference/mongo/mongo/get.xml create mode 100644 reference/mongo/mongocollection/get.xml create mode 100644 reference/mongo/mongodb/get.xml diff --git a/reference/mongo/examples.xml b/reference/mongo/examples.xml index 94dfd60cd5..78fd52ebb3 100644 --- a/reference/mongo/examples.xml +++ b/reference/mongo/examples.xml @@ -18,8 +18,8 @@ $m = new Mongo(); // select a database -$db = $m->selectDB("comedy"); -$collection = $db->selectCollection("cartoons"); +$db = $m->comedy; +$collection = $db->cartoons; // add an element $obj = array( "title" => "Calvin and Hobbes", "author" => "Bill Watterson" ); diff --git a/reference/mongo/mongo/get.xml b/reference/mongo/mongo/get.xml new file mode 100644 index 0000000000..f6dbb48203 --- /dev/null +++ b/reference/mongo/mongo/get.xml @@ -0,0 +1,87 @@ + + + + + + Mongo::__get + Gets a database + + + + &reftitle.description; + + public MongoDBMongo::__get + stringdbname + + + This is the cleanest way of getting a database. If the database name has any + special characters, Mongo::selectDB will need to be + used. However, in most cases, this should be sufficient. + +selectDB("foo"); +$db = $mongo->foo; + +?> +]]> + + + + + + &reftitle.parameters; + + + + + dbname + + + + The database name. + + + + + + + + + &reftitle.returnvalues; + + Returns a new db object. + + + + + &reftitle.errors; + + Throws InvalidArgumentException if the database name is invalid. + + + + + diff --git a/reference/mongo/mongocollection/batchinsert.xml b/reference/mongo/mongocollection/batchinsert.xml index a9d1d12938..0716cda71b 100644 --- a/reference/mongo/mongocollection/batchinsert.xml +++ b/reference/mongo/mongocollection/batchinsert.xml @@ -56,7 +56,7 @@ for ($i=0; $i<100; $i++) { } $m = new Mongo(); -$c = $m->selectCollection("foo", "bar.baz"); +$c = $m->foo->bar->baz; $c->batchInsert($batch); $cursor = $c->find()->sort(array("i" => 1)); diff --git a/reference/mongo/mongocollection/createdbref.xml b/reference/mongo/mongocollection/createdbref.xml index 13c504da5f..8f2c52cec6 100644 --- a/reference/mongo/mongocollection/createdbref.xml +++ b/reference/mongo/mongocollection/createdbref.xml @@ -48,8 +48,8 @@ selectCollection('songs'); -$playlists = $db->selectCollection('playlists'); +$songs = $db->songs; +$playlists = $db->playlists; // create a reference to a song $manamana = $songs->findOne(array('title' => 'Ma na ma na')); diff --git a/reference/mongo/mongocollection/deleteindex.xml b/reference/mongo/mongocollection/deleteindex.xml index 876c2fb22c..d214c6ad1e 100644 --- a/reference/mongo/mongocollection/deleteindex.xml +++ b/reference/mongo/mongocollection/deleteindex.xml @@ -51,7 +51,7 @@ selectCollection("example", "indices"); +$c = $m->example->indices; // create an index $c->ensureIndex(array("i"=>1)); diff --git a/reference/mongo/mongocollection/get.xml b/reference/mongo/mongocollection/get.xml new file mode 100644 index 0000000000..ab2c9af672 --- /dev/null +++ b/reference/mongo/mongocollection/get.xml @@ -0,0 +1,76 @@ + + + + + + MongoCollection::__get + Gets a collection + + + &reftitle.description; + + public MongoCollectionMongoCollection::__get + stringname + + + A concise syntax for getting a collection with a dot-separated name. If a + collection name contains strange characters, you may have to use + MongoDB::selectCollection instead. + +selectDB("foo")->selectCollection("bar.baz"); +$collection = $mongo->foo->bar->baz; + +?> +]]> + + + + + &reftitle.parameters; + + + + + name + + + + The next string in the collection name. + + + + + + + + &reftitle.returnvalues; + + Returns the collection. + + + + diff --git a/reference/mongo/mongocollection/getdbref.xml b/reference/mongo/mongocollection/getdbref.xml index 7ebeeb6290..875aaf53e7 100644 --- a/reference/mongo/mongocollection/getdbref.xml +++ b/reference/mongo/mongocollection/getdbref.xml @@ -48,7 +48,7 @@ selectCollection('playlists'); +$playlists = $db->playlists; $myList = $playlists->findOne(array('username' => 'me')); diff --git a/reference/mongo/mongocollection/getname.xml b/reference/mongo/mongocollection/getname.xml index ceeb64f372..d67a730cb4 100644 --- a/reference/mongo/mongocollection/getname.xml +++ b/reference/mongo/mongocollection/getname.xml @@ -35,7 +35,7 @@ selectDB("foo")->selectCollection("bar.baz"); +$c = $m->foo->bar->baz; echo "Working with collection " . $c->getName() . ".\n"; diff --git a/reference/mongo/mongocollection/remove.xml b/reference/mongo/mongocollection/remove.xml index c5f2403026..966df87ec1 100644 --- a/reference/mongo/mongocollection/remove.xml +++ b/reference/mongo/mongocollection/remove.xml @@ -59,7 +59,7 @@ selectCollection('radioactive'); +$radioactive = $db->radioactive; // count how much more plutonium there is $remaining = $radioactive->count(array('type' => 94)); diff --git a/reference/mongo/mongocollection/tostring.xml b/reference/mongo/mongocollection/tostring.xml index 991517ee39..7dfd1f31ed 100644 --- a/reference/mongo/mongocollection/tostring.xml +++ b/reference/mongo/mongocollection/tostring.xml @@ -35,9 +35,12 @@ selectDB("foo")->selectCollection("bar.baz"); -echo "Working with collection $c."; +$c1 = $m->foo->bar->baz; +echo "Working with collection $c1."; + +$c2 = $m->selectCollection('[]', '&'); +echo "Working with collection $c2."; ?> ]]> @@ -46,6 +49,7 @@ echo "Working with collection $c."; diff --git a/reference/mongo/mongocursor/tailable.xml b/reference/mongo/mongocursor/tailable.xml index 96c32358b6..ac829a847c 100644 --- a/reference/mongo/mongocursor/tailable.xml +++ b/reference/mongo/mongocursor/tailable.xml @@ -14,13 +14,18 @@ booleantailtrue - Mongo has a feature known as tailable cursors which are similar to the Unix "tail -f" command. + Mongo has a feature known as tailable cursors which are similar to the Unix + "tail -f" command. - Tailable means cursor is not closed when the last data is retrieved. rather, the cursor marks the final object's position. you can resume using the cursor later, from where it was located, if more data were received. + Tailable means cursor is not closed when the last data is retrieved. Rather, + the cursor marks the final object's position. you can resume using the + cursor later, from where it was located, if more data were received. - Like any "latent cursor", the cursor may become invalid at some point -- for example if that final object it references were deleted. Thus, you should be prepared to requery if the cursor is dead(). + Like any "latent cursor", the cursor may become invalid at some point -- for + example if that final object it references were deleted. Thus, you should be + prepared to requery if the cursor is MongoCursor::dead. diff --git a/reference/mongo/mongodb/get.xml b/reference/mongo/mongodb/get.xml new file mode 100644 index 0000000000..409e83eedb --- /dev/null +++ b/reference/mongo/mongodb/get.xml @@ -0,0 +1,76 @@ + + + + + + MongoDB::__get + Gets a collection + + + &reftitle.description; + + public MongoCollectionMongoDB::__get + stringname + + + This is the easiest way of getting a collection from a database object. If a + collection name contains strange characters, you may have to use + MongoDB::selectCollection instead. + +selectDB("foo")->selectCollection("bar"); +$collection = $mongo->foo->bar; + +?> +]]> + + + + + &reftitle.parameters; + + + + + name + + + + The name of the collection. + + + + + + + + &reftitle.returnvalues; + + Returns the collection. + + + + diff --git a/reference/mongo/mongodbref.xml b/reference/mongo/mongodbref.xml index b718ebcd19..169cafbc3e 100644 --- a/reference/mongo/mongodbref.xml +++ b/reference/mongo/mongodbref.xml @@ -25,8 +25,8 @@ selectCollection("people"); -$addresses = $db->selectCollection("addresses"); +$people = $db->people; +$addresses = $db->addresses; $myAddress = array("line 1" => "123 Main Street", "line 2" => null, diff --git a/reference/mongo/mongodbref/create.xml b/reference/mongo/mongodbref/create.xml index 10409acafc..5d3e85847b 100644 --- a/reference/mongo/mongodbref/create.xml +++ b/reference/mongo/mongodbref/create.xml @@ -72,8 +72,8 @@ selectCollection('addresses'); -$people = $db->selectCollection('people'); +$addresses = $db->addresses; +$people = $db->people; // save $address so it has an _id $addresses->insert($address); diff --git a/reference/mongo/tutorial.xml b/reference/mongo/tutorial.xml index fabfe04f01..355dd7e83a 100644 --- a/reference/mongo/tutorial.xml +++ b/reference/mongo/tutorial.xml @@ -32,7 +32,7 @@ $connection = new Mongo( "example.com:65432" ); // connect to a remote host at a selectDB( "dbname" ); +$db = $connection->dbname; ?> ]]> @@ -45,9 +45,9 @@ $db = $connection->selectDB( "dbname" ); selectDB( "mybiglongdbname" ); +$db = $connection->mybiglongdbname; // do some stuff -$db = $connection->selectDB( "mybiglongdbnme" ); +$db = $connection->mybiglongdbnme; // now connected to a different database! ]]> @@ -58,16 +58,17 @@ $db = $connection->selectDB( "mybiglongdbnme" );
Getting A Collection - To get a specific collection, use - MongoDB::selectCollection. Similarly to - MongoDB::selectDB, this creates the collection if it - does not already exist. + Getting a collection has the same syntax as getting a database: selectCollection( "foobar" ); +$db = $connection->baz +$collection = $db->foobar; + +// or, more succinctly +$collection = $connection->baz->foobar; ?> ]]> @@ -110,7 +111,7 @@ $doc = array( "name" => "MongoDB", selectDB( "foo" )->selectCollection( "bar" ); +$collection = $m->foo->bar; $collection->insert( $doc ); ?>