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

From: Date: Sat, 08 Dec 2012 16:23:32 +0000
Subject: svn: /phpdoc/en/trunk/reference/mongo/mongocollection/ find.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-10845@lists.php.net to get a copy of this message
preinheimer Sat, 08 Dec 2012 16:23:32 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=328711 Log: - Adding a basic search example, as well as searching for a child item. Rationale: I was helping a friend yesterday who is Learning MongoDB while they learn how to use the PHP Extension to it. They ended up trying to write a javascript based query to do a simple matching query. I hope these more simplistic examples will help people in that situation. Changed paths: U phpdoc/en/trunk/reference/mongo/mongocollection/find.xml Modified: phpdoc/en/trunk/reference/mongo/mongocollection/find.xml =================================================================== --- phpdoc/en/trunk/reference/mongo/mongocollection/find.xml 2012-12-08 12:16:45 UTC (rev 328710) +++ phpdoc/en/trunk/reference/mongo/mongocollection/find.xml 2012-12-08 16:23:32 UTC (rev 328711) @@ -67,6 +67,101 @@ <refsect1 role="examples"> &reftitle.examples; + <example> + <title><function>MongoCollection::find</function> example</title> + <para>This example demonstrates basic search options.</para> + <programlisting role="php"> +<![CDATA[ +<?php + +$m = new MongoClient(); +$db = $m->selectDB('test'); +$collection = new MongoCollection($db, 'produce'); + +// search for fruits +$fruitQuery = array('Type' => 'Fruit'); + +$cursor = $collection->find($fruitQuery); +foreach ($cursor as $doc) { + var_dump($doc); +} + +// search for produce that is sweet. Taste is a child of Details. +$sweetQuery = array('Details.Taste' => 'Sweet'); +echo "Sweet\n"; +$cursor = $collection->find($sweetQuery); +foreach ($cursor as $doc) { + var_dump($doc); +} + +?> +]]> + </programlisting> + &example.outputs; + <screen> +<![CDATA[ +array(4) { + ["_id"]=> + object(MongoId)#7 (1) { + ["$id"]=> + string(24) "50a87dd084f045a19b220dd6" + } + ["Name"]=> + string(5) "Apple" + ["Type"]=> + string(5) "Fruit" + ["Details"]=> + array(2) { + ["Taste"]=> + string(5) "Sweet" + ["Colour"]=> + string(3) "Red" + } +} +array(4) { + ["_id"]=> + object(MongoId)#8 (1) { + ["$id"]=> + string(24) "50a87de084f045a19b220dd7" + } + ["Name"]=> + string(5) "Lemon" + ["Type"]=> + string(5) "Fruit" + ["Details"]=> + array(2) { + ["Taste"]=> + string(4) "Sour" + ["Colour"]=> + string(5) "Green" + } +} + +Sweet: +array(4) { + ["_id"]=> + object(MongoId)#7 (1) { + ["$id"]=> + string(24) "50a87dd084f045a19b220dd6" + } + ["Name"]=> + string(5) "Apple" + ["Type"]=> + string(5) "Fruit" + ["Details"]=> + array(2) { + ["Taste"]=> + string(5) "Sweet" + ["Colour"]=> + string(3) "Red" + } +} +]]> + </screen> + <para> + See <classname>MongoCursor</classname> for more information how to work with cursors. + </para> + </example> <example> <title><function>MongoCollection::find</function> example</title> <para>This example demonstrates how to search for a range.</para>

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