com presentations: MongoDB talk for LoneStar PHP: mongo-lonestar12.xml slides/mongodb/connecting.xml slides/mongodb/idx-create-php.xml
slides/mongodb/limit-skip.xml slides/mongodb/query-advanced-example-array1.xml slides/mongodb/query-advanced-example-array2.xml
slides/mongodb/query-advanced-example-gte.xml slides/mongodb/sort.xml

From: Date: Tue, 26 Jun 2012 13:27:13 +0000
Subject: com presentations: MongoDB talk for LoneStar PHP: mongo-lonestar12.xml slides/mongodb/connecting.xml slides/mongodb/idx-create-php.xml
slides/mongodb/limit-skip.xml slides/mongodb/query-advanced-example-array1.xml slides/mongodb/query-advanced-example-array2.xml
slides/mongodb/query-advanced-example-gte.xml slides/mongodb/sort.xml
Groups: php.pres 
Request: Send a blank email to pres+get-1827@lists.php.net to get a copy of this message
Commit: 794448800b4d4c865dba3d7094f97976c81a1000 Author: Derick Rethans <github@derickrethans.nl> Tue, 26 Jun 2012 15:27:13 +0200 Parents: 7817ebe17de87b3dc5406156ddad2aa7b9e9fe49 Branches: master Link: http://git.php.net/?p=presentations.git;a=commitdiff;h=794448800b4d4c865dba3d7094f97976c81a1000 Log: MongoDB talk for LoneStar PHP Changed paths: A mongo-lonestar12.xml M slides/mongodb/connecting.xml A slides/mongodb/idx-create-php.xml M slides/mongodb/limit-skip.xml M slides/mongodb/query-advanced-example-array1.xml M slides/mongodb/query-advanced-example-array2.xml M slides/mongodb/query-advanced-example-gte.xml M slides/mongodb/sort.xml

diff --git a/mongo-lonestar12.xml b/mongo-lonestar12.xml new file mode 100644 index 0000000..e488ffd --- /dev/null +++ b/mongo-lonestar12.xml @@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="utf-8"?> +<presentation css="10gen-strict.css"> +<topic>mongoDB</topic> +<title>MongoDB and PHP</title> +<event>LoneStar PHP</event> +<location>Addison, TX, US</location> +<date>Jun 30th, 2012</date> +<speaker>Derick Rethans</speaker> +<email>derick@10gen.com</email> +<twitter>derickr</twitter> +<url>http://derickrethans.nl/talks.html</url> +<joindin>http://joind.in/6353</joindin> +<slide>slides/mongodb/title.xml</slide> +<slide>slides/mongodb/me.xml</slide> + +<slide>slides/mongodb/what-is-mongodb.xml</slide> +- document storage +- no configuration (or very little) +- scalable and fast + +<slide>slides/mongodb/mongod-install.xml</slide> +<slide>slides/mongodb/mongo-extension.xml</slide> +- install + - driver + - mongodb + +<slide>slides/mongodb/collections-documents.xml</slide> + +<slide>slides/mongodb/connecting.xml</slide> + +<slide>slides/mongodb/document.xml</slide> +- json +- typed +- ids + +<slide>slides/mongodb/insert.xml</slide> +- single + +<slide>slides/mongodb/types.xml</slide> +- php types +- extra types (int32/64) +- id +<slide>slides/mongodb/id.xml</slide> +<slide>slides/mongodb/safe.xml</slide> +<slide>slides/mongodb/safe2.xml</slide> + +<slide>slides/mongodb/query.xml</slide> +- findOne +- find + +<slide>slides/mongodb/cursors.xml</slide> +- cursor +<slide>slides/mongodb/sort.xml</slide> +- sort +<slide>slides/mongodb/limit-skip.xml</slide> +- limit/skip + + +<slide>slides/mongodb/query-advanced-ops.xml</slide> +- regexp + +<slide>slides/mongodb/query-advanced-example-gte.xml</slide> +<slide>slides/mongodb/query-advanced-example-array1.xml</slide> +<slide>slides/mongodb/query-advanced-example-array2.xml</slide> + +<slide>slides/mongodb/update.xml</slide> +<slide>slides/mongodb/update-modifiers.xml</slide> +<slide>slides/mongodb/update2.xml</slide> +<slide>slides/mongodb/update2a.xml</slide> +<slide>slides/mongodb/upsert.xml</slide> +<slide>slides/mongodb/update-modifiers3.xml</slide> +- atomic update ops +- find and modify +- upsert + +<slide>slides/mongodb/commands-distinct.xml</slide> +<slide>slides/mongodb/commands.xml</slide> +<slide>slides/mongodb/commands-aggregation.xml</slide> + +<slide>slides/mongodb/idx-create-php.xml</slide> + +<slide>slides/mongodb/idx-recap1.xml</slide> +<slide>slides/mongodb/idx-recap2.xml</slide> +<slide>slides/mongodb/idx-recap3.xml</slide> + +<slide>slides/mongodb/resources.xml</slide> + +</presentation> diff --git a/slides/mongodb/connecting.xml b/slides/mongodb/connecting.xml index a01a085..74fd477 100644 --- a/slides/mongodb/connecting.xml +++ b/slides/mongodb/connecting.xml @@ -1,7 +1,7 @@ <slide> <title>Connecting to MongoDB</title> -<blurb>No tables or collections have to do be explicitly created:</blurb> +<blurb>No databases or collections have to do be explicitly created:</blurb> <break /> <example><![CDATA[<?php diff --git a/slides/mongodb/idx-create-php.xml b/slides/mongodb/idx-create-php.xml new file mode 100644 index 0000000..2e05b28 --- /dev/null +++ b/slides/mongodb/idx-create-php.xml @@ -0,0 +1,21 @@ +<slide> +<title>Creating Indexes</title> + +<blurb>The %_id% field is always indexed. Additional indexes can be created with %ensureIndex%:</blurb> + +<example><![CDATA[ +<?php +$m = new Mongo; +$c = $m->demo->cities; + +// Create an index on the name attribute +$c->ensureIndex( array( 'name' => 1 ) ); + +// Create a compound index on country code and feature code +$c->ensureIndex( array( 'country_code' => 1, 'feature_code' => 1 ) ); + +// Create a unique index on the area field of timezone: +$c->ensureIndex( array( 'timezone.area' => 1 ) ); +]]> +</example> +</slide> diff --git a/slides/mongodb/limit-skip.xml b/slides/mongodb/limit-skip.xml index 953b847..91dc319 100644 --- a/slides/mongodb/limit-skip.xml +++ b/slides/mongodb/limit-skip.xml @@ -3,17 +3,14 @@ <example result="1"><![CDATA[<?php $m = new Mongo(); -$c = $m->demo->articles; +$c = $m->demo->cities; -$cursor = $c->find(); -$cursor->sort( array( '_id' => 1 ) ) - ->limit( 3 ) - ->skip( 3 ); +$cursor = $c->find( array( 'country_code' => 'RU' ) ) + ->sort( array( 'name' => 1 ) ) + ->limit( 5 )->skip( 25 ); -// Only now does the query get send -foreach ( $cursor as $r ) -{ - echo $r['_id'], "\n"; +foreach ( $cursor as $r ) { + var_dump( $r['name'] ); } ?>]]></example> </slide> diff --git a/slides/mongodb/query-advanced-example-array1.xml b/slides/mongodb/query-advanced-example-array1.xml index 223ccea..db36b13 100644 --- a/slides/mongodb/query-advanced-example-array1.xml +++ b/slides/mongodb/query-advanced-example-array1.xml @@ -4,45 +4,42 @@ <div effect="fade-out"> <example result="2"><![CDATA[<?php $m = new Mongo; -$c = $m->demo->circus; - +$c = $m->demo->continent; $c->drop(); $c->insert( array( - '_id' => 'circ1', - 'name' => 'Diaspora', - 'performers' => 43, - 'elephpants' => array ( - array ( 'name' => 'Annabelle', 'colour' => 'pink', 'year' => 1964 ), - array ( 'name' => 'Chunee', 'colour' => 'blue', 'year' => 1826 ) + 'name' => 'South America', + 'cities' => array( + array( "name" => "Buenos Aires", "population" => 13076300, "dem" => 131 ), + array( "name" => "São Paulo", "population" => 10021295, "dem" => 769 ), ) ) ); - $c->insert( array( - '_id' => 'circ2', - 'name' => 'Sensible', - 'performers' => 27, - 'elephpants' => array ( - array ( 'name' => 'Kandula', 'colour' => 'pink', 'year' => 2001 ), - array ( 'name' => 'Kolakolli', 'colour' => 'blue', 'year' => 2006 ) + 'name' => 'Asia', + 'cities' => array( + array( "name" => "Karachi", "population" => 11624219, "dem" => 38 ), + array( "name" => "Moscow", "population" => 10381222, "dem" => 144 ), + array( "name" => "İstanbul", "population" => 11174257, "dem" => 39 ), ) ) ); ?>]]></example> -</div> -<blurb>Find circuses which have blue elephpants after 1900.</blurb> +<blurb>Contitent with a city of more than 11 million people and above 100 +meter.</blurb> +</div> <div effect="fade-in"> -<example result="1"><![CDATA[<?php ini_set( 'xdebug.var_display_max_depth', 4 ); +<example result="1"><![CDATA[<?php $m = new Mongo; -$c = $m->demo->circus; -$r = $c->find( - array( 'elephpants.colour' => 'blue', 'elephpants.year' => array( '$gt' => 1900 ) ) -); +$c = $m->demo->continent; +$r = $c->find( array( + 'cities.population' => array( '$gte' => 11000000 ), + 'cities.dem' => array( '$gte' => 100 ), +) ); + foreach( $r as $c ) { - echo $c['name'], ': '; - foreach( $c['elephpants'] as $elephpant ) { - echo "\n- ", join( ", ", $elephpant ); + echo $c['name'], "\n"; + foreach( $c['cities'] as $city ) { + echo '- ', $city['name'], ': ', $city['population'], ' - ', $city['dem'], "\n"; } - echo "\n\n"; } ?>]]></example> </div> diff --git a/slides/mongodb/query-advanced-example-array2.xml b/slides/mongodb/query-advanced-example-array2.xml index 90545be..3c2a82d 100644 --- a/slides/mongodb/query-advanced-example-array2.xml +++ b/slides/mongodb/query-advanced-example-array2.xml @@ -3,17 +3,21 @@ <example result="1"><![CDATA[<?php $m = new Mongo; -$c = $m->demo->circus; -$r = $c->find( [ - 'elephpants' => - [ '$elemMatch' => [ 'colour' => 'blue', 'year' => [ '$gt' => 1900 ] ] ] -] ); +$c = $m->demo->continent; +$r = $c->find( array( + 'cities' => array( + '$elemMatch' => array( + 'population' => array( '$gte' => 11000000 ), + 'dem' => array( '$gte' => 100 ), + ) + ) +) ); + foreach( $r as $c ) { - echo $c['name'], ': '; - foreach( $c['elephpants'] as $elephpant ) { - echo "\n- ", join( ", ", $elephpant ); + echo $c['name'], "\n"; + foreach( $c['cities'] as $city ) { + echo '- ', $city['name'], ': ', $city['population'], ' - ', $city['dem'], "\n"; } - echo "\n\n"; } ?>]]></example> </slide> diff --git a/slides/mongodb/query-advanced-example-gte.xml b/slides/mongodb/query-advanced-example-gte.xml index 40000f2..1bd193a 100644 --- a/slides/mongodb/query-advanced-example-gte.xml +++ b/slides/mongodb/query-advanced-example-gte.xml @@ -2,38 +2,37 @@ <title>Querying: $gte</title> <div effect="fade-out"> -<example result="2"><![CDATA[<?php +<example><![CDATA[<?php $m = new Mongo; -$c = $m->demo->circus; - -$c->insert( array( - '_id' => 'circ1', - 'name' => 'Diaspora', - 'performers' => 43, -) ); - -$c->insert( array( - '_id' => 'circ2', - 'name' => 'Sensible', - 'performers' => 27, -) ); +$c = $m->demo->cities; +$c->insert( array( "name" => "Buenos Aires", "population" => 13076300 ) ); +$c->insert( array( "name" => "Dhaka", "population" => 10356500 ) ); +$c->insert( array( "name" => "São Paulo", "population" => 10021295 ) ); +$c->insert( array( "name" => "Shanghai", "population" => 14608512 ) ); +$c->insert( array( "name" => "Delhi", "population" => 10927986 ) ); +$c->insert( array( "name" => "Mumbai", "population" => 12691836 ) ); +$c->insert( array( "name" => "Seoul", "population" => 10349312 ) ); +$c->insert( array( "name" => "Mexico City", "population" => 12294193 ) ); ?>]]></example> </div> -<blurb>Find circuses with 40 or more performers.</blurb> +<blurb>Find cities with more than 12 million inhabitants.</blurb> <div effect="fade-in"> <example result="1"><![CDATA[<?php $m = new Mongo; -$c = $m->demo->circus; +$c = $m->demo->cities; -$r = $c->findOne( +$r = $c->find( // query - array( 'performers' => array( '$gte' => 40 ) ), + array( 'population' => array( '$gte' => 12000000 ) ), // projection - array( 'name' => true, 'performers' => true ) + array( 'name' => true, 'population' => true, '_id' => false ) ); -var_dump( $r ); -?>]]></example> + +foreach( $r as $res ) +{ + echo $res['name'], ': ', $res['population'], "\n"; +}]]></example> </div> </slide> diff --git a/slides/mongodb/sort.xml b/slides/mongodb/sort.xml index 724b78c..542e0ad 100644 --- a/slides/mongodb/sort.xml +++ b/slides/mongodb/sort.xml @@ -3,13 +3,13 @@ <example result="1"><![CDATA[<?php $m = new Mongo(); -$c = $m->demo->articles; +$c = $m->demo->cities; -$cursor = $c->find()->sort( array( '_id' => -1 ) ); +$cursor = $c->find( array( 'country_code' => 'IS' ) ) + ->sort( array( 'name' => -1 ) ); -foreach ( $cursor as $r ) -{ - var_dump( $r ); +foreach ( $cursor as $r ) { + var_dump( $r['name'] ); } ?>]]></example> </slide>
« previous php.pres (#1827) next »