com presentations: Convert array() syntax to []: slides/mongodb/excercise03-add-like.xml slides/mongodb/excercise03-push-to-add-review.xml
slides/mongodb/geo-aggregation2-php.xml slides/mongodb/id.xml slides/mongodb/indexes-geo.xml slides/mongodb/indexes.xml slides/mongodb/insert-php.xml
slides/mongodb/insert.xml slides/mongodb/limit-skip.xml slides/mongodb/osm-schema1.xml slides/mongodb/osm-schema2.xml slides/mongodb/osm-schema3.xml
slides/mongo
| From: | Derick Rethans | Date: | Sun, 17 May 2015 17:42:19 +0000 |
| Subject: | com presentations: Convert array() syntax to []: slides/mongodb/excercise03-add-like.xml slides/mongodb/excercise03-push-to-add-review.xml slides/mongodb/geo-aggregation2-php.xml slides/mongodb/id.xml slides/mongodb/indexes-geo.xml slides/mongodb/indexes.xml slides/mongodb/insert-php.xml slides/mongodb/insert.xml slides/mongodb/limit-skip.xml slides/mongodb/osm-schema1.xml slides/mongodb/osm-schema2.xml slides/mongodb/osm-schema3.xml slides/mongo |
||
| Groups: | php.pres | ||
| Request: | Send a blank email to pres+get-2092@lists.php.net to get a copy of this message | ||
Commit: a1eb30d719d49ab5fee8baf5cffabbdf1bff755e
Author: Jeremy Mikola <jmikola@gmail.com> Sun, 17 May 2015 12:42:19 -0500
Parents: db0e9a68d61b9276321d389835edc40e95503f29
Branches: master
Link: http://git.php.net/?p=presentations.git;a=commitdiff;h=a1eb30d719d49ab5fee8baf5cffabbdf1bff755e
Log:
Convert array() syntax to []
Changed paths:
M slides/mongodb/excercise03-add-like.xml
M slides/mongodb/excercise03-push-to-add-review.xml
M slides/mongodb/geo-aggregation2-php.xml
M slides/mongodb/id.xml
M slides/mongodb/indexes-geo.xml
M slides/mongodb/indexes.xml
M slides/mongodb/insert-php.xml
M slides/mongodb/insert.xml
M slides/mongodb/limit-skip.xml
M slides/mongodb/osm-schema1.xml
M slides/mongodb/osm-schema2.xml
M slides/mongodb/osm-schema3.xml
M slides/mongodb/osm-schema4.xml
M slides/mongodb/php-connection-string.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/query.xml
M slides/mongodb/query2.xml
M slides/mongodb/read-preference.xml
M slides/mongodb/repl-tagging-example.xml
M slides/mongodb/safe.xml
M slides/mongodb/safe2.xml
M slides/mongodb/safe3.xml
M slides/mongodb/sort.xml
M slides/mongodb/update-modifiers.xml
M slides/mongodb/update-modifiers3.xml
M slides/mongodb/update-modifiers4.xml
M slides/mongodb/update.xml
M slides/mongodb/update2.xml
M slides/mongodb/upsert.xml
M slides/mongodb/write-import-script-result.xml
M slides/mongodb/write-import-script2.xml
diff --git a/slides/mongodb/excercise03-add-like.xml b/slides/mongodb/excercise03-add-like.xml index 197f16b..3982fa3 100644 --- a/slides/mongodb/excercise03-add-like.xml +++ b/slides/mongodb/excercise03-add-like.xml @@ -20,8 +20,8 @@ $m = new MongoClient; $c = $m->demo->whisky; $c->update( - array( 'name' => 'Glenfiddich 15', 'notes.user_name' => 'Derick' ), - array( '$inc => array( 'notes.$.likes' => 1 ) ) + [ 'name' => 'Glenfiddich 15', 'notes.user_name' => 'Derick' ], + [ '$inc => [ 'notes.$.likes' => 1 ] ] ); ?>]]></example> </div> diff --git a/slides/mongodb/excercise03-push-to-add-review.xml b/slides/mongodb/excercise03-push-to-add-review.xml index 5995de1..02b452c 100644 --- a/slides/mongodb/excercise03-push-to-add-review.xml +++ b/slides/mongodb/excercise03-push-to-add-review.xml @@ -19,16 +19,16 @@ $m = new MongoClient; $c = $m->demo->whisky; -$newReview = array( +$newReview = [ user_name => "Michael", date => new MongoDate(strtotime("2013-10-01")), note => "No peat, but fruity", rating => 1, -); +]; $c->update( - array( 'name' => 'Glenfiddich 15' ), - array( '$push => array( 'notes' => $newReview ) ) + [ 'name' => 'Glenfiddich 15' ], + [ '$push => [ 'notes' => $newReview ] ] ); ?>]]></example> </div> diff --git a/slides/mongodb/geo-aggregation2-php.xml b/slides/mongodb/geo-aggregation2-php.xml index ecad8a7..7ea4ae7 100644 --- a/slides/mongodb/geo-aggregation2-php.xml +++ b/slides/mongodb/geo-aggregation2-php.xml @@ -12,21 +12,21 @@ $center = new GeoJSONPoint( $maxDist = 500; // in meters $rEarth = 6371000; -$res = $c->aggregate( array( - '$geoNear' => array( +$res = $c->aggregate( [ + '$geoNear' => [ 'near' => $center->p, 'distanceField' => 'distance', 'distanceMultiplier' => $rEarth, 'maxDistance' => $maxDist / $rEarth, 'spherical' => true, - 'query' => array( - '$or' => array( - array( TAGS => 'amenity=pub' ), - array( TAGS => 'amenity=bar' ) - ) - ), - ) -) ); + 'query' => [ + '$or' => [ + [ TAGS => 'amenity=pub' ], + [ TAGS => 'amenity=bar' ] + ] + ], + ] +] ); ]]></example> </div> @@ -39,21 +39,21 @@ $center = new GeoJSONPoint( $maxDist = 500; // in meters $rEarth = 6371000; -$res = $c->aggregate( array( - |ff0000|'$geoNear' => array(| +$res = $c->aggregate( [ + |ff0000|'$geoNear' => [| |ff0000|'near' => $center->p,| 'distanceField' => 'distance', 'distanceMultiplier' => $rEarth, 'maxDistance' => $maxDist / $rEarth, |ff0000|'spherical' => true,| - |ff0000|'query' => array(| - |ff0000|'$or' => array(| - |ff0000|array( TAGS => 'amenity=pub' ),| - |ff0000|array( TAGS => 'amenity=bar' )| - |ff0000|)| - |ff0000|),| - |ff0000|)| -) ); + |ff0000|'query' => [| + |ff0000|'$or' => [| + |ff0000|[ TAGS => 'amenity=pub' ],| + |ff0000|[ TAGS => 'amenity=bar' ]| + |ff0000|]| + |ff0000|],| + |ff0000|]| +] ); ]]></example> </div> @@ -67,21 +67,21 @@ $center = new GeoJSONPoint( |ff0000|$maxDist = 500; // in meters| |ff0000|$rEarth = 6371000;| -$res = $c->aggregate( array( - '$geoNear' => array( +$res = $c->aggregate( [ + '$geoNear' => [ 'near' => $center->p, |ff0000|'distanceField' => 'distance',| |ff0000|'distanceMultiplier' => $rEarth,| |ff0000|'maxDistance' => $maxDist / $rEarth,| 'spherical' => true, - 'query' => array( - '$or' => array( - array( TAGS => 'amenity=pub' ), - array( TAGS => 'amenity=bar' ) - ) - ), - ) -) ); + 'query' => [ + '$or' => [ + [ TAGS => 'amenity=pub' ], + [ TAGS => 'amenity=bar' ] + ] + ], + ] +] ); ]]></example> </div> diff --git a/slides/mongodb/id.xml b/slides/mongodb/id.xml index 046d3fa..96d3882 100644 --- a/slides/mongodb/id.xml +++ b/slides/mongodb/id.xml @@ -12,7 +12,7 @@ $c = $m->demo->articles; $c->insert( [ 'name' => 'Derick', '_id' => 'derickr' ] ); -$d = array( 'name' => 'Derick' ); +$d = [ 'name' => 'Derick' ]; $c->insert( $d ); var_dump( $d ); ?>]]></example> diff --git a/slides/mongodb/indexes-geo.xml b/slides/mongodb/indexes-geo.xml index 4e5eb9c..51b977c 100644 --- a/slides/mongodb/indexes-geo.xml +++ b/slides/mongodb/indexes-geo.xml @@ -6,7 +6,7 @@ <example result="0"><![CDATA[<?php $m = new MongoClient; $c = $m->demo->pubs; $c->drop(); -$c->ensureIndex( array( 'l' => '2d' ) ); +$c->ensureIndex( [ 'l' => '2d' ] ); $c->insert([ 'name' => 'Betsy Smith', 'l' => [ -0.193, 51.537 ] ]); $c->insert([ 'name' => 'London Tavern', 'l' => [ -0.202, 51.545 ] ]); diff --git a/slides/mongodb/indexes.xml b/slides/mongodb/indexes.xml index 056017b..53a276f 100644 --- a/slides/mongodb/indexes.xml +++ b/slides/mongodb/indexes.xml @@ -18,8 +18,8 @@ $m = new MongoClient; $c = $m->demo->elephpants; $c->drop(); -$c->insert( array( '_id' => 'ele1', 'name' => 'Jumbo' ) ); -$c->insert( array( '_id' => 'ele2', 'name' => 'Tantor' ) ); +$c->insert( [ '_id' => 'ele1', 'name' => 'Jumbo' ] ); +$c->insert( [ '_id' => 'ele2', 'name' => 'Tantor' ] ); var_dump( $c->find( [ '_id' => 'ele1' ] )->explain() ); ?>]]> diff --git a/slides/mongodb/insert-php.xml b/slides/mongodb/insert-php.xml index 97d8c48..3edc215 100644 --- a/slides/mongodb/insert-php.xml +++ b/slides/mongodb/insert-php.xml @@ -2,20 +2,20 @@ <title>Inserting a document</title> <example result="0"><![CDATA[<?php -$document = array( +$document = [ "_id" => "derickr", "name" => "Derick Rethans", - "talks" => array( - array( + "talks" => [ + [ "title" => "Profiling PHP Applications", "url" => "http://derickrethans.nl/talks/profiling-phptour.pdf", - ), - array( + ], + [ "title" => "Xdebug", "url" => "http://derickrethans.nl/talks/xdebug-phpbcn11.pdf", - ) - ) -); + ] + ] +]; $m = new MongoClient(); var_dump( $m->demo->talks->insert( $document ) ); diff --git a/slides/mongodb/insert.xml b/slides/mongodb/insert.xml index fb24a33..a6e0717 100644 --- a/slides/mongodb/insert.xml +++ b/slides/mongodb/insert.xml @@ -22,20 +22,20 @@ <div effect="fade-in-out"> <example result="0"><![CDATA[<?php -$document = array( +$document = [ "_id" => "derickr", "name" => "Derick Rethans", - "talks" => array( - array( + "talks" => [ + [ "title" => "Profiling PHP Applications", "url" => "http://derickrethans.nl/talks/profiling-phptour.pdf", - ), - array( + ], + [ "title" => "Xdebug", "url" => "http://derickrethans.nl/talks/xdebug-phpbcn11.pdf", - ) - ) -); + ] + ] +]; $m = new MongoClient(); var_dump( $m->demo->talks->insert( $document ) ); diff --git a/slides/mongodb/limit-skip.xml b/slides/mongodb/limit-skip.xml index 839da2c..b5480d9 100644 --- a/slides/mongodb/limit-skip.xml +++ b/slides/mongodb/limit-skip.xml @@ -5,8 +5,8 @@ $m = new MongoClient(); $c = $m->demo->cities; -$cursor = $c->find( array( 'country_code' => 'RU' ) ) - ->sort( array( 'name' => 1 ) ) +$cursor = $c->find( [ 'country_code' => 'RU' ] ) + ->sort( [ 'name' => 1 ] ) ->limit( 5 )->skip( 25 ); foreach ( $cursor as $r ) { diff --git a/slides/mongodb/osm-schema1.xml b/slides/mongodb/osm-schema1.xml index 239d581..bd16877 100644 --- a/slides/mongodb/osm-schema1.xml +++ b/slides/mongodb/osm-schema1.xml @@ -1,13 +1,13 @@ <slide> <title>Tags as a key/value combination</title> -<example>$doc = array( +<example>$doc = [ 'tags' => [ 'name' => 'A440', 'highway' => 'secondary', 'oneway' => 'yes' ] -); +]; $db->poi->ensureIndex( [ 'tags.name' => 1 ] ); $db->poi->ensureIndex( [ 'tags.highway' => 1 ] ); $db->poi->ensureIndex( [ 'tags.oneway' => 1 ] ); diff --git a/slides/mongodb/osm-schema2.xml b/slides/mongodb/osm-schema2.xml index 1dab339..9b2ce73 100644 --- a/slides/mongodb/osm-schema2.xml +++ b/slides/mongodb/osm-schema2.xml @@ -1,13 +1,13 @@ <slide> <title>Tags as dictionary</title> -<example>$doc = array( +<example>$doc = [ 'tags' => [ [ 'k' => 'name', 'v' => 'A440' ], [ 'k' => 'highway', 'v' => 'secondary' ], [ 'k' => 'oneway', 'v' => 'yes' ] ] -); +]; $db->poi->ensureIndex( [ 'tags.v' => 1, 'tags.k' => 1 ] ); // Road with name=Strand diff --git a/slides/mongodb/osm-schema3.xml b/slides/mongodb/osm-schema3.xml index dbf7cda..9ca8895 100644 --- a/slides/mongodb/osm-schema3.xml +++ b/slides/mongodb/osm-schema3.xml @@ -1,13 +1,13 @@ <slide> <title>Tags as documents</title> -<example>$doc = array( +<example>$doc = [ 'tags' => [ [ 'name' => 'A440' ], [ 'highway' => 'secondary' ], [ 'oneway' => 'yes' ], ] -); +]; $db->poi->ensureIndex( [ 'tags' => 1 ] ); // Road with name=Strand diff --git a/slides/mongodb/osm-schema4.xml b/slides/mongodb/osm-schema4.xml index f71b391..47d6b58 100644 --- a/slides/mongodb/osm-schema4.xml +++ b/slides/mongodb/osm-schema4.xml @@ -1,13 +1,13 @@ <slide> <title>Tags as concatenated strings</title> -<example>$doc = array( +<example>$doc = [ 'tags' => [ 'name=A440', 'highway=secondary', 'oneway=yes' ] -); +]; $db->poi->ensureIndex( [ 'tags' => 1 ] ); // Road with name=Strand diff --git a/slides/mongodb/php-connection-string.xml b/slides/mongodb/php-connection-string.xml index f73e92c..cdfe9e2 100644 --- a/slides/mongodb/php-connection-string.xml +++ b/slides/mongodb/php-connection-string.xml @@ -2,7 +2,7 @@ <title>Connection String</title> <example result="0"><![CDATA[<?php -$options = array( 'replicaSet' => 'seta' ); +$options = [ 'replicaSet' => 'seta' ]; $m = new MongoClient( 'mongodb://localhost:13000/?replicaSet=seta' ); diff --git a/slides/mongodb/query-advanced-example-array1.xml b/slides/mongodb/query-advanced-example-array1.xml index 50709a6..ca3b7be 100644 --- a/slides/mongodb/query-advanced-example-array1.xml +++ b/slides/mongodb/query-advanced-example-array1.xml @@ -5,21 +5,21 @@ <example result="2"><![CDATA[<?php $m = new MongoClient; $c = $m->demo->continent; $c->drop(); -$c->insert( array( +$c->insert( [ '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( + 'cities' => [ + [ "name" => "Buenos Aires", "population" => 13076300, "dem" => 131 ], + [ "name" => "São Paulo", "population" => 10021295, "dem" => 769 ], + ] +] ); +$c->insert( [ '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 ), - ) -) ); + 'cities' => [ + [ "name" => "Karachi", "population" => 11624219, "dem" => 38 ], + [ "name" => "Moscow", "population" => 10381222, "dem" => 144 ], + [ "name" => "İstanbul", "population" => 11174257, "dem" => 39 ], + ] +] ); ?>]]></example> <blurb>Contitent with a city of more than 11 million people and above 100 @@ -30,10 +30,10 @@ meter.</blurb> <example result="1"><![CDATA[<?php $m = new MongoClient; $c = $m->demo->continent; -$r = $c->find( array( - 'cities.population' => array( '$gte' => 11000000 ), - 'cities.dem' => array( '$gte' => 100 ), -) ); +$r = $c->find( [ + 'cities.population' => [ '$gte' => 11000000 ], + 'cities.dem' => [ '$gte' => 100 ], +] ); foreach( $r as $c ) { echo $c['name'], "\n"; diff --git a/slides/mongodb/query-advanced-example-array2.xml b/slides/mongodb/query-advanced-example-array2.xml index e5c21b7..bbc3865 100644 --- a/slides/mongodb/query-advanced-example-array2.xml +++ b/slides/mongodb/query-advanced-example-array2.xml @@ -4,14 +4,14 @@ <example result="1"><![CDATA[<?php $m = new MongoClient; $c = $m->demo->continent; -$r = $c->find( array( - 'cities' => array( - '$elemMatch' => array( - 'population' => array( '$gte' => 11000000 ), - 'dem' => array( '$gte' => 100 ), - ) - ) -) ); +$r = $c->find( [ + 'cities' => [ + '$elemMatch' => [ + 'population' => [ '$gte' => 11000000 ], + 'dem' => [ '$gte' => 100 ], + ] + ] +] ); foreach( $r as $c ) { echo $c['name'], "\n"; diff --git a/slides/mongodb/query-advanced-example-gte.xml b/slides/mongodb/query-advanced-example-gte.xml index 0cf4f9f..d370690 100644 --- a/slides/mongodb/query-advanced-example-gte.xml +++ b/slides/mongodb/query-advanced-example-gte.xml @@ -5,14 +5,14 @@ <example><![CDATA[<?php $m = new MongoClient; $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 ) ); +$c->insert( [ "name" => "Buenos Aires", "population" => 13076300 ] ); +$c->insert( [ "name" => "Dhaka", "population" => 10356500 ] ); +$c->insert( [ "name" => "São Paulo", "population" => 10021295 ] ); +$c->insert( [ "name" => "Shanghai", "population" => 14608512 ] ); +$c->insert( [ "name" => "Delhi", "population" => 10927986 ] ); +$c->insert( [ "name" => "Mumbai", "population" => 12691836 ] ); +$c->insert( [ "name" => "Seoul", "population" => 10349312 ] ); +$c->insert( [ "name" => "Mexico City", "population" => 12294193 ] ); ?>]]></example> </div> @@ -25,9 +25,9 @@ $c = $m->demo->cities; $r = $c->find( // query - array( 'population' => array( '$gte' => 12000000 ) ), + [ 'population' => [ '$gte' => 12000000 ] ], // projection - array( 'name' => true, 'population' => true, '_id' => false ) + [ 'name' => true, 'population' => true, '_id' => false ] ); foreach( $r as $res ) diff --git a/slides/mongodb/query.xml b/slides/mongodb/query.xml index ddb0e2a..b0c81fe 100644 --- a/slides/mongodb/query.xml +++ b/slides/mongodb/query.xml @@ -7,13 +7,11 @@ $m = new MongoClient(); $record = $m->demo->talks->findOne(); // Search on the _id field being 'derickr' -$record = $m->demo->talks->findOne( array( '_id' => 'derickr' ) ); +$record = $m->demo->talks->findOne( [ '_id' => 'derickr' ] ); // Search on the 'talks' embedded document's 'title' field $record = $m->demo->talks->findOne( - array( - 'talks.title' => 'Xdebug' - ) + [ 'talks.title' => 'Xdebug' ] ); ?>]]></example> </slide> diff --git a/slides/mongodb/query2.xml b/slides/mongodb/query2.xml index 0e00b90..a46879f 100644 --- a/slides/mongodb/query2.xml +++ b/slides/mongodb/query2.xml @@ -6,8 +6,8 @@ $m = new MongoClient(); // Find with 'projection' $record = $m->demo->talks->findOne( - array( 'talks.title' => 'Xdebug' ), - array( 'name' => 1, 'talks.url' => 1 ) + [ 'talks.title' => 'Xdebug' ], + [ 'name' => 1, 'talks.url' => 1 ] ); ?>]]></example> </slide> diff --git a/slides/mongodb/read-preference.xml b/slides/mongodb/read-preference.xml index 7d7b86d..80b84b6 100644 --- a/slides/mongodb/read-preference.xml +++ b/slides/mongodb/read-preference.xml @@ -13,7 +13,7 @@ $c->find(...); <example result="0"><![CDATA[<?php $m = new MongoClient( 'mongodb://localhost:13000/?replicaSet=poiset' ); $c = $m->phpunit->test; -$c->setReadPreference( Mongo::RP_SECONDARY, array( 'dc' => 'europe' ) ); +$c->setReadPreference( Mongo::RP_SECONDARY, [ 'dc' => 'europe' ] ); $c->find(...); ?>]]></example> diff --git a/slides/mongodb/repl-tagging-example.xml b/slides/mongodb/repl-tagging-example.xml index 9063b31..f9b0e7a 100644 --- a/slides/mongodb/repl-tagging-example.xml +++ b/slides/mongodb/repl-tagging-example.xml @@ -21,6 +21,6 @@ <blurb>From PHP, enforce the write tags by:</blurb> <example><![CDATA[ -$c->insert( array( … ), array( 'safe' => 'allUses' ) ); +$c->insert( [ … ], [ 'safe' => 'allUses' ] ); ]]></example> </slide> diff --git a/slides/mongodb/safe.xml b/slides/mongodb/safe.xml index 57551f8..bf90173 100644 --- a/slides/mongodb/safe.xml +++ b/slides/mongodb/safe.xml @@ -10,8 +10,8 @@ $m = new MongoClient; $c = $m->demo->talks; try { - $c->insert( array( '_id' => 'derickr' ) ); - $c->insert( array( '_id' => 'derickr' ) ); + $c->insert( [ '_id' => 'derickr' ] ); + $c->insert( [ '_id' => 'derickr' ] ); } catch ( Exception $e ) { echo $e->getMessage(), "\n"; } @@ -24,8 +24,8 @@ try { $m = new MongoClient('mongodb://localhost/?w=0'); $c = $m->demo->talks; -$c->insert( array( '_id' => 'derickr' ) ); -$c->insert( array( '_id' => 'derickr' ) ); +$c->insert( [ '_id' => 'derickr' ] ); +$c->insert( [ '_id' => 'derickr' ] ); ?>]]></example> </div> </slide> diff --git a/slides/mongodb/safe2.xml b/slides/mongodb/safe2.xml index 275a2dc..fffbb79 100644 --- a/slides/mongodb/safe2.xml +++ b/slides/mongodb/safe2.xml @@ -3,10 +3,10 @@ <blurb>Safeness levels:</blurb> <list> - <bullet>Confirm change recorded in memory: %array( 'w' => 1 );%</bullet> - <bullet>Confirm inclusion in journal: %array( 'j' => true );%</bullet> - <bullet>Confirm committed to disk: %array( 'fsync' => true );%</bullet> - <bullet>Confirm replication: %array( 'w' => 2 );%</bullet> + <bullet>Confirm change recorded in memory: %[ 'w' => 1 ];%</bullet> + <bullet>Confirm inclusion in journal: %[ 'j' => true ];%</bullet> + <bullet>Confirm committed to disk: %[ 'fsync' => true ];%</bullet> + <bullet>Confirm replication: %[ 'w' => 2 ];%</bullet> </list> <example result="1"><![CDATA[<?php @@ -14,8 +14,8 @@ $m = new Mongo(); $c = $m->demo->talks; $c->insert( - array( '_id' => 'mongodb' ), // document - array( 'safe' => true, 'w' => 2 ) // options + [ '_id' => 'mongodb' ], // document + [ 'safe' => true, 'w' => 2 ] // options ); ?>]]></example> diff --git a/slides/mongodb/safe3.xml b/slides/mongodb/safe3.xml index b34f6f4..41bb76b 100644 --- a/slides/mongodb/safe3.xml +++ b/slides/mongodb/safe3.xml @@ -10,8 +10,8 @@ $m = new MongoClient( 'mongodb://localhost:13000/?replSet=seta&w=2' ); $c = $m->demo->talks; -$c->insert( array( '_id' => 'mongodb' ) ); -$c->insert( array( '_id' => 'mongodb' ) ); +$c->insert( [ '_id' => 'mongodb' ] ); +$c->insert( [ '_id' => 'mongodb' ] ); ?>]]></example> <list> diff --git a/slides/mongodb/sort.xml b/slides/mongodb/sort.xml index 749ed37..ebc1525 100644 --- a/slides/mongodb/sort.xml +++ b/slides/mongodb/sort.xml @@ -5,8 +5,8 @@ $m = new MongoClient(); $c = $m->demo->cities; -$cursor = $c->find( array( 'country_code' => 'IS' ) ) - ->sort( array( 'name' => -1 ) ); +$cursor = $c->find( [ 'country_code' => 'IS' ] ) + ->sort( [ 'name' => -1 ] ); foreach ( $cursor as $r ) { var_dump( $r['name'] ); diff --git a/slides/mongodb/update-modifiers.xml b/slides/mongodb/update-modifiers.xml index 2473d87..4f8f48d 100644 --- a/slides/mongodb/update-modifiers.xml +++ b/slides/mongodb/update-modifiers.xml @@ -6,21 +6,21 @@ $m = new MongoClient; $c = $m->demo->presentations; $c->remove(); -$c->insert( array( +$c->insert( [ '_id' => 'mongo-tut-zendcon12', 'name' => 'Hands-On MongoDB' -) ); +] ); $c->update( - array( 'name' => 'Hands-On MongoDB' ), // criteria - array( '$set' => array( 'lastviewed' => time() ) ) // modifiers + [ 'name' => 'Hands-On MongoDB' ], // criteria + [ '$set' => [ 'lastviewed' => time() ] ] // modifiers ); /* document is now: -array( +[ '_id' => 'mongo-tut-zendcon12', 'name' => 'Hands-On MongoDB' 'lastviewed' => 1350296073, -) */ +] */ ?>]]></example> </slide> diff --git a/slides/mongodb/update-modifiers3.xml b/slides/mongodb/update-modifiers3.xml index 83ea373..dc1a9db 100644 --- a/slides/mongodb/update-modifiers3.xml +++ b/slides/mongodb/update-modifiers3.xml @@ -11,14 +11,12 @@ <example result="1"><![CDATA[<?php $m = new MongoClient; $c = $m->demo->circus; $c->remove(); -$c->insert( array( '_id' => 'circ5', 'name' => 'Funny Led' ) ); +$c->insert( [ '_id' => 'circ5', 'name' => 'Funny Led' ] ); $c->update( - array( '_id' => 'circ5' ), - array( '$push' => array( - 'elephpants' => array( 'name' => 'Bobo', 'year' => 2012 ) ) - ) + [ '_id' => 'circ5' ], + [ '$push' => [ 'elephpants' => [ 'name' => 'Bobo', 'year' => 2012 ] ] ] ); -var_dump( $c->findOne( array( 'name' => 'Funny Led' ), array( 'elephpants' => true ) ) ); +var_dump( $c->findOne( [ 'name' => 'Funny Led' ], [ 'elephpants' => true ] ) ); ?>]]></example> </slide> diff --git a/slides/mongodb/update-modifiers4.xml b/slides/mongodb/update-modifiers4.xml index d9cbb35..49dd7ed 100644 --- a/slides/mongodb/update-modifiers4.xml +++ b/slides/mongodb/update-modifiers4.xml @@ -10,17 +10,17 @@ $m = new MongoClient; $c = $m->demo->bits; $c->remove(); -$c->insert( array( 'bitmask' => 0b1001 ) ); +$c->insert( [ 'bitmask' => 0b1001 ] ); echo decbin( $c->findOne()['bitmask'] ), "\n"; -$c->update( array(), array( '$bit' => array( 'bitmask' => array( 'and' => 0b0101 ) ) ) ); +$c->update( [], [ '$bit' => [ 'bitmask' => [ 'and' => 0b0101 ] ] ] ); echo decbin( $c->findOne()['bitmask'] ), "\n"; -$c->update( array(), array( '$bit' => array( 'bitmask' => array( 'or' => 0b10100 ) ) ) ); +$c->update( [], [ '$bit' => [ 'bitmask' => [ 'or' => 0b10100 ] ] ] ); echo decbin( $c->findOne()['bitmask'] ), "\n"; // this is not in yet ;-) -$c->update( array(), array( '$bit' => array( 'bitmask' => array( 'xor' => 0b01110 ) ) ) ); +$c->update( [], [ '$bit' => [ 'bitmask' => [ 'xor' => 0b01110 ] ] ] ); echo decbin( $c->findOne()['bitmask'] ), "\n"; ?>]]></example> </slide> diff --git a/slides/mongodb/update.xml b/slides/mongodb/update.xml index bec578c..3206eee 100644 --- a/slides/mongodb/update.xml +++ b/slides/mongodb/update.xml @@ -6,14 +6,14 @@ $m = new MongoClient; $c = $m->demo->elephpants; $c->remove(); -$c->insert( array( '_id' => 'e42', 'name' => 'Kamubpo' ) ); -var_dump( $c->findOne( array( '_id' => 'e42' ) ) ); +$c->insert( [ '_id' => 'e42', 'name' => 'Kamubpo' ] ); +var_dump( $c->findOne( [ '_id' => 'e42' ] ) ); -$c->update( array( '_id' => 'e42' ), array( 'name' => 'Bo Tat' ) ); -var_dump( $c->findOne( array( '_id' => 'e42' ) ) ); +$c->update( [ '_id' => 'e42' ], [ 'name' => 'Bo Tat' ] ); +var_dump( $c->findOne( [ '_id' => 'e42' ] ) ); -$c->update( array( 'name' => 'Bo Tat' ), array( 'age' => '17' ) ); -var_dump( $c->findOne( array( '_id' => 'e42' ) ) ); +$c->update( [ 'name' => 'Bo Tat' ], [ 'age' => '17' ] ); +var_dump( $c->findOne( [ '_id' => 'e42' ] ) ); ?>]]></example> <blurb>update() replaces the document matching criteria entirely with a new object.</blurb> diff --git a/slides/mongodb/update2.xml b/slides/mongodb/update2.xml index dcacc5f..bf67d33 100644 --- a/slides/mongodb/update2.xml +++ b/slides/mongodb/update2.xml @@ -8,10 +8,10 @@ $m = new MongoClient; $c = $m->demo->elephpants; $c->drop(); -$c->insert( array( '_id' => 'e42', 'name' => 'Kamubpo', 'age' => 17 ) ); -$c->insert( array( '_id' => 'e43', 'name' => 'Denali', 'age' => 17 ) ); +$c->insert( [ '_id' => 'e42', 'name' => 'Kamubpo', 'age' => 17 ] ); +$c->insert( [ '_id' => 'e43', 'name' => 'Denali', 'age' => 17 ] ); -$c->update( array( 'age' => 17 ), array( '$inc' => array( 'age' => 1 ) ) ); +$c->update( [ 'age' => 17 ], [ '$inc' => [ 'age' => 1 ] ] ); var_dump( iterator_to_array( $c->find() ) ); ?>]]></example> diff --git a/slides/mongodb/upsert.xml b/slides/mongodb/upsert.xml index 701e1f4..bee2ceb 100644 --- a/slides/mongodb/upsert.xml +++ b/slides/mongodb/upsert.xml @@ -10,11 +10,11 @@ $c = $m->demo->elephpants; $c->drop(); function birthDay( $c, $name ) { $c->update( - array( 'name' => $name ), // criteria - array( '$inc' => array( 'age' => 1 ) ), // update spec - array( 'upsert' => true ) // options + [ 'name' => $name ], // criteria + [ '$inc' => [ 'age' => 1 ] ], // update spec + [ 'upsert' => true ] // options ); - echo $c->findOne( array( 'name' => 'Santon' ) )['age'], "\n"; + echo $c->findOne( [ 'name' => 'Santon' ] )['age'], "\n"; } birthDay( $c, 'Santon' ); diff --git a/slides/mongodb/write-import-script-result.xml b/slides/mongodb/write-import-script-result.xml index 08da078..11266e0 100644 --- a/slides/mongodb/write-import-script-result.xml +++ b/slides/mongodb/write-import-script-result.xml @@ -17,8 +17,8 @@ $d = $m->demo->poi; $d->drop(); // 3 ADD: Create an index on "name" and a "2d" index on "loc" -$d->ensureIndex( array( 'loc' => '2d' ) ); -$d->ensureIndex( array( 'name' => 1 ) ); +$d->ensureIndex( [ 'loc' => '2d' ] ); +$d->ensureIndex( [ 'name' => 1 ] ); var_dump($d->getIndexInfo()); ]]></example> diff --git a/slides/mongodb/write-import-script2.xml b/slides/mongodb/write-import-script2.xml index 4e97689..251b506 100644 --- a/slides/mongodb/write-import-script2.xml +++ b/slides/mongodb/write-import-script2.xml @@ -7,8 +7,8 @@ </list> <example><![CDATA[<?php // 1 ADD: Indexes for the tags -$d->ensureIndex( array( 'tags_indexed' => 1 ) ); -$d->ensureIndex( array( 'tags_indexed.k' => 1, 'tags_indexed.v' => 1 ) ); +$d->ensureIndex( [ 'tags_indexed' => 1 ] ); +$d->ensureIndex( [ 'tags_indexed.k' => 1, 'tags_indexed.v' => 1 ] ); var_dump($d->getIndexInfo()); ]]></example>
diff --git a/slides/mongodb/excercise03-add-like.xml b/slides/mongodb/excercise03-add-like.xml index 197f16b..3982fa3 100644 --- a/slides/mongodb/excercise03-add-like.xml +++ b/slides/mongodb/excercise03-add-like.xml @@ -20,8 +20,8 @@ $m = new MongoClient; $c = $m->demo->whisky; $c->update( - array( 'name' => 'Glenfiddich 15', 'notes.user_name' => 'Derick' ), - array( '$inc => array( 'notes.$.likes' => 1 ) ) + [ 'name' => 'Glenfiddich 15', 'notes.user_name' => 'Derick' ], + [ '$inc => [ 'notes.$.likes' => 1 ] ] ); ?>]]></example> </div> diff --git a/slides/mongodb/excercise03-push-to-add-review.xml b/slides/mongodb/excercise03-push-to-add-review.xml index 5995de1..02b452c 100644 --- a/slides/mongodb/excercise03-push-to-add-review.xml +++ b/slides/mongodb/excercise03-push-to-add-review.xml @@ -19,16 +19,16 @@ $m = new MongoClient; $c = $m->demo->whisky; -$newReview = array( +$newReview = [ user_name => "Michael", date => new MongoDate(strtotime("2013-10-01")), note => "No peat, but fruity", rating => 1, -); +]; $c->update( - array( 'name' => 'Glenfiddich 15' ), - array( '$push => array( 'notes' => $newReview ) ) + [ 'name' => 'Glenfiddich 15' ], + [ '$push => [ 'notes' => $newReview ] ] ); ?>]]></example> </div> diff --git a/slides/mongodb/geo-aggregation2-php.xml b/slides/mongodb/geo-aggregation2-php.xml index ecad8a7..7ea4ae7 100644 --- a/slides/mongodb/geo-aggregation2-php.xml +++ b/slides/mongodb/geo-aggregation2-php.xml @@ -12,21 +12,21 @@ $center = new GeoJSONPoint( $maxDist = 500; // in meters $rEarth = 6371000; -$res = $c->aggregate( array( - '$geoNear' => array( +$res = $c->aggregate( [ + '$geoNear' => [ 'near' => $center->p, 'distanceField' => 'distance', 'distanceMultiplier' => $rEarth, 'maxDistance' => $maxDist / $rEarth, 'spherical' => true, - 'query' => array( - '$or' => array( - array( TAGS => 'amenity=pub' ), - array( TAGS => 'amenity=bar' ) - ) - ), - ) -) ); + 'query' => [ + '$or' => [ + [ TAGS => 'amenity=pub' ], + [ TAGS => 'amenity=bar' ] + ] + ], + ] +] ); ]]></example> </div> @@ -39,21 +39,21 @@ $center = new GeoJSONPoint( $maxDist = 500; // in meters $rEarth = 6371000; -$res = $c->aggregate( array( - |ff0000|'$geoNear' => array(| +$res = $c->aggregate( [ + |ff0000|'$geoNear' => [| |ff0000|'near' => $center->p,| 'distanceField' => 'distance', 'distanceMultiplier' => $rEarth, 'maxDistance' => $maxDist / $rEarth, |ff0000|'spherical' => true,| - |ff0000|'query' => array(| - |ff0000|'$or' => array(| - |ff0000|array( TAGS => 'amenity=pub' ),| - |ff0000|array( TAGS => 'amenity=bar' )| - |ff0000|)| - |ff0000|),| - |ff0000|)| -) ); + |ff0000|'query' => [| + |ff0000|'$or' => [| + |ff0000|[ TAGS => 'amenity=pub' ],| + |ff0000|[ TAGS => 'amenity=bar' ]| + |ff0000|]| + |ff0000|],| + |ff0000|]| +] ); ]]></example> </div> @@ -67,21 +67,21 @@ $center = new GeoJSONPoint( |ff0000|$maxDist = 500; // in meters| |ff0000|$rEarth = 6371000;| -$res = $c->aggregate( array( - '$geoNear' => array( +$res = $c->aggregate( [ + '$geoNear' => [ 'near' => $center->p, |ff0000|'distanceField' => 'distance',| |ff0000|'distanceMultiplier' => $rEarth,| |ff0000|'maxDistance' => $maxDist / $rEarth,| 'spherical' => true, - 'query' => array( - '$or' => array( - array( TAGS => 'amenity=pub' ), - array( TAGS => 'amenity=bar' ) - ) - ), - ) -) ); + 'query' => [ + '$or' => [ + [ TAGS => 'amenity=pub' ], + [ TAGS => 'amenity=bar' ] + ] + ], + ] +] ); ]]></example> </div> diff --git a/slides/mongodb/id.xml b/slides/mongodb/id.xml index 046d3fa..96d3882 100644 --- a/slides/mongodb/id.xml +++ b/slides/mongodb/id.xml @@ -12,7 +12,7 @@ $c = $m->demo->articles; $c->insert( [ 'name' => 'Derick', '_id' => 'derickr' ] ); -$d = array( 'name' => 'Derick' ); +$d = [ 'name' => 'Derick' ]; $c->insert( $d ); var_dump( $d ); ?>]]></example> diff --git a/slides/mongodb/indexes-geo.xml b/slides/mongodb/indexes-geo.xml index 4e5eb9c..51b977c 100644 --- a/slides/mongodb/indexes-geo.xml +++ b/slides/mongodb/indexes-geo.xml @@ -6,7 +6,7 @@ <example result="0"><![CDATA[<?php $m = new MongoClient; $c = $m->demo->pubs; $c->drop(); -$c->ensureIndex( array( 'l' => '2d' ) ); +$c->ensureIndex( [ 'l' => '2d' ] ); $c->insert([ 'name' => 'Betsy Smith', 'l' => [ -0.193, 51.537 ] ]); $c->insert([ 'name' => 'London Tavern', 'l' => [ -0.202, 51.545 ] ]); diff --git a/slides/mongodb/indexes.xml b/slides/mongodb/indexes.xml index 056017b..53a276f 100644 --- a/slides/mongodb/indexes.xml +++ b/slides/mongodb/indexes.xml @@ -18,8 +18,8 @@ $m = new MongoClient; $c = $m->demo->elephpants; $c->drop(); -$c->insert( array( '_id' => 'ele1', 'name' => 'Jumbo' ) ); -$c->insert( array( '_id' => 'ele2', 'name' => 'Tantor' ) ); +$c->insert( [ '_id' => 'ele1', 'name' => 'Jumbo' ] ); +$c->insert( [ '_id' => 'ele2', 'name' => 'Tantor' ] ); var_dump( $c->find( [ '_id' => 'ele1' ] )->explain() ); ?>]]> diff --git a/slides/mongodb/insert-php.xml b/slides/mongodb/insert-php.xml index 97d8c48..3edc215 100644 --- a/slides/mongodb/insert-php.xml +++ b/slides/mongodb/insert-php.xml @@ -2,20 +2,20 @@ <title>Inserting a document</title> <example result="0"><![CDATA[<?php -$document = array( +$document = [ "_id" => "derickr", "name" => "Derick Rethans", - "talks" => array( - array( + "talks" => [ + [ "title" => "Profiling PHP Applications", "url" => "http://derickrethans.nl/talks/profiling-phptour.pdf", - ), - array( + ], + [ "title" => "Xdebug", "url" => "http://derickrethans.nl/talks/xdebug-phpbcn11.pdf", - ) - ) -); + ] + ] +]; $m = new MongoClient(); var_dump( $m->demo->talks->insert( $document ) ); diff --git a/slides/mongodb/insert.xml b/slides/mongodb/insert.xml index fb24a33..a6e0717 100644 --- a/slides/mongodb/insert.xml +++ b/slides/mongodb/insert.xml @@ -22,20 +22,20 @@ <div effect="fade-in-out"> <example result="0"><![CDATA[<?php -$document = array( +$document = [ "_id" => "derickr", "name" => "Derick Rethans", - "talks" => array( - array( + "talks" => [ + [ "title" => "Profiling PHP Applications", "url" => "http://derickrethans.nl/talks/profiling-phptour.pdf", - ), - array( + ], + [ "title" => "Xdebug", "url" => "http://derickrethans.nl/talks/xdebug-phpbcn11.pdf", - ) - ) -); + ] + ] +]; $m = new MongoClient(); var_dump( $m->demo->talks->insert( $document ) ); diff --git a/slides/mongodb/limit-skip.xml b/slides/mongodb/limit-skip.xml index 839da2c..b5480d9 100644 --- a/slides/mongodb/limit-skip.xml +++ b/slides/mongodb/limit-skip.xml @@ -5,8 +5,8 @@ $m = new MongoClient(); $c = $m->demo->cities; -$cursor = $c->find( array( 'country_code' => 'RU' ) ) - ->sort( array( 'name' => 1 ) ) +$cursor = $c->find( [ 'country_code' => 'RU' ] ) + ->sort( [ 'name' => 1 ] ) ->limit( 5 )->skip( 25 ); foreach ( $cursor as $r ) { diff --git a/slides/mongodb/osm-schema1.xml b/slides/mongodb/osm-schema1.xml index 239d581..bd16877 100644 --- a/slides/mongodb/osm-schema1.xml +++ b/slides/mongodb/osm-schema1.xml @@ -1,13 +1,13 @@ <slide> <title>Tags as a key/value combination</title> -<example>$doc = array( +<example>$doc = [ 'tags' => [ 'name' => 'A440', 'highway' => 'secondary', 'oneway' => 'yes' ] -); +]; $db->poi->ensureIndex( [ 'tags.name' => 1 ] ); $db->poi->ensureIndex( [ 'tags.highway' => 1 ] ); $db->poi->ensureIndex( [ 'tags.oneway' => 1 ] ); diff --git a/slides/mongodb/osm-schema2.xml b/slides/mongodb/osm-schema2.xml index 1dab339..9b2ce73 100644 --- a/slides/mongodb/osm-schema2.xml +++ b/slides/mongodb/osm-schema2.xml @@ -1,13 +1,13 @@ <slide> <title>Tags as dictionary</title> -<example>$doc = array( +<example>$doc = [ 'tags' => [ [ 'k' => 'name', 'v' => 'A440' ], [ 'k' => 'highway', 'v' => 'secondary' ], [ 'k' => 'oneway', 'v' => 'yes' ] ] -); +]; $db->poi->ensureIndex( [ 'tags.v' => 1, 'tags.k' => 1 ] ); // Road with name=Strand diff --git a/slides/mongodb/osm-schema3.xml b/slides/mongodb/osm-schema3.xml index dbf7cda..9ca8895 100644 --- a/slides/mongodb/osm-schema3.xml +++ b/slides/mongodb/osm-schema3.xml @@ -1,13 +1,13 @@ <slide> <title>Tags as documents</title> -<example>$doc = array( +<example>$doc = [ 'tags' => [ [ 'name' => 'A440' ], [ 'highway' => 'secondary' ], [ 'oneway' => 'yes' ], ] -); +]; $db->poi->ensureIndex( [ 'tags' => 1 ] ); // Road with name=Strand diff --git a/slides/mongodb/osm-schema4.xml b/slides/mongodb/osm-schema4.xml index f71b391..47d6b58 100644 --- a/slides/mongodb/osm-schema4.xml +++ b/slides/mongodb/osm-schema4.xml @@ -1,13 +1,13 @@ <slide> <title>Tags as concatenated strings</title> -<example>$doc = array( +<example>$doc = [ 'tags' => [ 'name=A440', 'highway=secondary', 'oneway=yes' ] -); +]; $db->poi->ensureIndex( [ 'tags' => 1 ] ); // Road with name=Strand diff --git a/slides/mongodb/php-connection-string.xml b/slides/mongodb/php-connection-string.xml index f73e92c..cdfe9e2 100644 --- a/slides/mongodb/php-connection-string.xml +++ b/slides/mongodb/php-connection-string.xml @@ -2,7 +2,7 @@ <title>Connection String</title> <example result="0"><![CDATA[<?php -$options = array( 'replicaSet' => 'seta' ); +$options = [ 'replicaSet' => 'seta' ]; $m = new MongoClient( 'mongodb://localhost:13000/?replicaSet=seta' ); diff --git a/slides/mongodb/query-advanced-example-array1.xml b/slides/mongodb/query-advanced-example-array1.xml index 50709a6..ca3b7be 100644 --- a/slides/mongodb/query-advanced-example-array1.xml +++ b/slides/mongodb/query-advanced-example-array1.xml @@ -5,21 +5,21 @@ <example result="2"><![CDATA[<?php $m = new MongoClient; $c = $m->demo->continent; $c->drop(); -$c->insert( array( +$c->insert( [ '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( + 'cities' => [ + [ "name" => "Buenos Aires", "population" => 13076300, "dem" => 131 ], + [ "name" => "São Paulo", "population" => 10021295, "dem" => 769 ], + ] +] ); +$c->insert( [ '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 ), - ) -) ); + 'cities' => [ + [ "name" => "Karachi", "population" => 11624219, "dem" => 38 ], + [ "name" => "Moscow", "population" => 10381222, "dem" => 144 ], + [ "name" => "İstanbul", "population" => 11174257, "dem" => 39 ], + ] +] ); ?>]]></example> <blurb>Contitent with a city of more than 11 million people and above 100 @@ -30,10 +30,10 @@ meter.</blurb> <example result="1"><![CDATA[<?php $m = new MongoClient; $c = $m->demo->continent; -$r = $c->find( array( - 'cities.population' => array( '$gte' => 11000000 ), - 'cities.dem' => array( '$gte' => 100 ), -) ); +$r = $c->find( [ + 'cities.population' => [ '$gte' => 11000000 ], + 'cities.dem' => [ '$gte' => 100 ], +] ); foreach( $r as $c ) { echo $c['name'], "\n"; diff --git a/slides/mongodb/query-advanced-example-array2.xml b/slides/mongodb/query-advanced-example-array2.xml index e5c21b7..bbc3865 100644 --- a/slides/mongodb/query-advanced-example-array2.xml +++ b/slides/mongodb/query-advanced-example-array2.xml @@ -4,14 +4,14 @@ <example result="1"><![CDATA[<?php $m = new MongoClient; $c = $m->demo->continent; -$r = $c->find( array( - 'cities' => array( - '$elemMatch' => array( - 'population' => array( '$gte' => 11000000 ), - 'dem' => array( '$gte' => 100 ), - ) - ) -) ); +$r = $c->find( [ + 'cities' => [ + '$elemMatch' => [ + 'population' => [ '$gte' => 11000000 ], + 'dem' => [ '$gte' => 100 ], + ] + ] +] ); foreach( $r as $c ) { echo $c['name'], "\n"; diff --git a/slides/mongodb/query-advanced-example-gte.xml b/slides/mongodb/query-advanced-example-gte.xml index 0cf4f9f..d370690 100644 --- a/slides/mongodb/query-advanced-example-gte.xml +++ b/slides/mongodb/query-advanced-example-gte.xml @@ -5,14 +5,14 @@ <example><![CDATA[<?php $m = new MongoClient; $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 ) ); +$c->insert( [ "name" => "Buenos Aires", "population" => 13076300 ] ); +$c->insert( [ "name" => "Dhaka", "population" => 10356500 ] ); +$c->insert( [ "name" => "São Paulo", "population" => 10021295 ] ); +$c->insert( [ "name" => "Shanghai", "population" => 14608512 ] ); +$c->insert( [ "name" => "Delhi", "population" => 10927986 ] ); +$c->insert( [ "name" => "Mumbai", "population" => 12691836 ] ); +$c->insert( [ "name" => "Seoul", "population" => 10349312 ] ); +$c->insert( [ "name" => "Mexico City", "population" => 12294193 ] ); ?>]]></example> </div> @@ -25,9 +25,9 @@ $c = $m->demo->cities; $r = $c->find( // query - array( 'population' => array( '$gte' => 12000000 ) ), + [ 'population' => [ '$gte' => 12000000 ] ], // projection - array( 'name' => true, 'population' => true, '_id' => false ) + [ 'name' => true, 'population' => true, '_id' => false ] ); foreach( $r as $res ) diff --git a/slides/mongodb/query.xml b/slides/mongodb/query.xml index ddb0e2a..b0c81fe 100644 --- a/slides/mongodb/query.xml +++ b/slides/mongodb/query.xml @@ -7,13 +7,11 @@ $m = new MongoClient(); $record = $m->demo->talks->findOne(); // Search on the _id field being 'derickr' -$record = $m->demo->talks->findOne( array( '_id' => 'derickr' ) ); +$record = $m->demo->talks->findOne( [ '_id' => 'derickr' ] ); // Search on the 'talks' embedded document's 'title' field $record = $m->demo->talks->findOne( - array( - 'talks.title' => 'Xdebug' - ) + [ 'talks.title' => 'Xdebug' ] ); ?>]]></example> </slide> diff --git a/slides/mongodb/query2.xml b/slides/mongodb/query2.xml index 0e00b90..a46879f 100644 --- a/slides/mongodb/query2.xml +++ b/slides/mongodb/query2.xml @@ -6,8 +6,8 @@ $m = new MongoClient(); // Find with 'projection' $record = $m->demo->talks->findOne( - array( 'talks.title' => 'Xdebug' ), - array( 'name' => 1, 'talks.url' => 1 ) + [ 'talks.title' => 'Xdebug' ], + [ 'name' => 1, 'talks.url' => 1 ] ); ?>]]></example> </slide> diff --git a/slides/mongodb/read-preference.xml b/slides/mongodb/read-preference.xml index 7d7b86d..80b84b6 100644 --- a/slides/mongodb/read-preference.xml +++ b/slides/mongodb/read-preference.xml @@ -13,7 +13,7 @@ $c->find(...); <example result="0"><![CDATA[<?php $m = new MongoClient( 'mongodb://localhost:13000/?replicaSet=poiset' ); $c = $m->phpunit->test; -$c->setReadPreference( Mongo::RP_SECONDARY, array( 'dc' => 'europe' ) ); +$c->setReadPreference( Mongo::RP_SECONDARY, [ 'dc' => 'europe' ] ); $c->find(...); ?>]]></example> diff --git a/slides/mongodb/repl-tagging-example.xml b/slides/mongodb/repl-tagging-example.xml index 9063b31..f9b0e7a 100644 --- a/slides/mongodb/repl-tagging-example.xml +++ b/slides/mongodb/repl-tagging-example.xml @@ -21,6 +21,6 @@ <blurb>From PHP, enforce the write tags by:</blurb> <example><![CDATA[ -$c->insert( array( … ), array( 'safe' => 'allUses' ) ); +$c->insert( [ … ], [ 'safe' => 'allUses' ] ); ]]></example> </slide> diff --git a/slides/mongodb/safe.xml b/slides/mongodb/safe.xml index 57551f8..bf90173 100644 --- a/slides/mongodb/safe.xml +++ b/slides/mongodb/safe.xml @@ -10,8 +10,8 @@ $m = new MongoClient; $c = $m->demo->talks; try { - $c->insert( array( '_id' => 'derickr' ) ); - $c->insert( array( '_id' => 'derickr' ) ); + $c->insert( [ '_id' => 'derickr' ] ); + $c->insert( [ '_id' => 'derickr' ] ); } catch ( Exception $e ) { echo $e->getMessage(), "\n"; } @@ -24,8 +24,8 @@ try { $m = new MongoClient('mongodb://localhost/?w=0'); $c = $m->demo->talks; -$c->insert( array( '_id' => 'derickr' ) ); -$c->insert( array( '_id' => 'derickr' ) ); +$c->insert( [ '_id' => 'derickr' ] ); +$c->insert( [ '_id' => 'derickr' ] ); ?>]]></example> </div> </slide> diff --git a/slides/mongodb/safe2.xml b/slides/mongodb/safe2.xml index 275a2dc..fffbb79 100644 --- a/slides/mongodb/safe2.xml +++ b/slides/mongodb/safe2.xml @@ -3,10 +3,10 @@ <blurb>Safeness levels:</blurb> <list> - <bullet>Confirm change recorded in memory: %array( 'w' => 1 );%</bullet> - <bullet>Confirm inclusion in journal: %array( 'j' => true );%</bullet> - <bullet>Confirm committed to disk: %array( 'fsync' => true );%</bullet> - <bullet>Confirm replication: %array( 'w' => 2 );%</bullet> + <bullet>Confirm change recorded in memory: %[ 'w' => 1 ];%</bullet> + <bullet>Confirm inclusion in journal: %[ 'j' => true ];%</bullet> + <bullet>Confirm committed to disk: %[ 'fsync' => true ];%</bullet> + <bullet>Confirm replication: %[ 'w' => 2 ];%</bullet> </list> <example result="1"><![CDATA[<?php @@ -14,8 +14,8 @@ $m = new Mongo(); $c = $m->demo->talks; $c->insert( - array( '_id' => 'mongodb' ), // document - array( 'safe' => true, 'w' => 2 ) // options + [ '_id' => 'mongodb' ], // document + [ 'safe' => true, 'w' => 2 ] // options ); ?>]]></example> diff --git a/slides/mongodb/safe3.xml b/slides/mongodb/safe3.xml index b34f6f4..41bb76b 100644 --- a/slides/mongodb/safe3.xml +++ b/slides/mongodb/safe3.xml @@ -10,8 +10,8 @@ $m = new MongoClient( 'mongodb://localhost:13000/?replSet=seta&w=2' ); $c = $m->demo->talks; -$c->insert( array( '_id' => 'mongodb' ) ); -$c->insert( array( '_id' => 'mongodb' ) ); +$c->insert( [ '_id' => 'mongodb' ] ); +$c->insert( [ '_id' => 'mongodb' ] ); ?>]]></example> <list> diff --git a/slides/mongodb/sort.xml b/slides/mongodb/sort.xml index 749ed37..ebc1525 100644 --- a/slides/mongodb/sort.xml +++ b/slides/mongodb/sort.xml @@ -5,8 +5,8 @@ $m = new MongoClient(); $c = $m->demo->cities; -$cursor = $c->find( array( 'country_code' => 'IS' ) ) - ->sort( array( 'name' => -1 ) ); +$cursor = $c->find( [ 'country_code' => 'IS' ] ) + ->sort( [ 'name' => -1 ] ); foreach ( $cursor as $r ) { var_dump( $r['name'] ); diff --git a/slides/mongodb/update-modifiers.xml b/slides/mongodb/update-modifiers.xml index 2473d87..4f8f48d 100644 --- a/slides/mongodb/update-modifiers.xml +++ b/slides/mongodb/update-modifiers.xml @@ -6,21 +6,21 @@ $m = new MongoClient; $c = $m->demo->presentations; $c->remove(); -$c->insert( array( +$c->insert( [ '_id' => 'mongo-tut-zendcon12', 'name' => 'Hands-On MongoDB' -) ); +] ); $c->update( - array( 'name' => 'Hands-On MongoDB' ), // criteria - array( '$set' => array( 'lastviewed' => time() ) ) // modifiers + [ 'name' => 'Hands-On MongoDB' ], // criteria + [ '$set' => [ 'lastviewed' => time() ] ] // modifiers ); /* document is now: -array( +[ '_id' => 'mongo-tut-zendcon12', 'name' => 'Hands-On MongoDB' 'lastviewed' => 1350296073, -) */ +] */ ?>]]></example> </slide> diff --git a/slides/mongodb/update-modifiers3.xml b/slides/mongodb/update-modifiers3.xml index 83ea373..dc1a9db 100644 --- a/slides/mongodb/update-modifiers3.xml +++ b/slides/mongodb/update-modifiers3.xml @@ -11,14 +11,12 @@ <example result="1"><![CDATA[<?php $m = new MongoClient; $c = $m->demo->circus; $c->remove(); -$c->insert( array( '_id' => 'circ5', 'name' => 'Funny Led' ) ); +$c->insert( [ '_id' => 'circ5', 'name' => 'Funny Led' ] ); $c->update( - array( '_id' => 'circ5' ), - array( '$push' => array( - 'elephpants' => array( 'name' => 'Bobo', 'year' => 2012 ) ) - ) + [ '_id' => 'circ5' ], + [ '$push' => [ 'elephpants' => [ 'name' => 'Bobo', 'year' => 2012 ] ] ] ); -var_dump( $c->findOne( array( 'name' => 'Funny Led' ), array( 'elephpants' => true ) ) ); +var_dump( $c->findOne( [ 'name' => 'Funny Led' ], [ 'elephpants' => true ] ) ); ?>]]></example> </slide> diff --git a/slides/mongodb/update-modifiers4.xml b/slides/mongodb/update-modifiers4.xml index d9cbb35..49dd7ed 100644 --- a/slides/mongodb/update-modifiers4.xml +++ b/slides/mongodb/update-modifiers4.xml @@ -10,17 +10,17 @@ $m = new MongoClient; $c = $m->demo->bits; $c->remove(); -$c->insert( array( 'bitmask' => 0b1001 ) ); +$c->insert( [ 'bitmask' => 0b1001 ] ); echo decbin( $c->findOne()['bitmask'] ), "\n"; -$c->update( array(), array( '$bit' => array( 'bitmask' => array( 'and' => 0b0101 ) ) ) ); +$c->update( [], [ '$bit' => [ 'bitmask' => [ 'and' => 0b0101 ] ] ] ); echo decbin( $c->findOne()['bitmask'] ), "\n"; -$c->update( array(), array( '$bit' => array( 'bitmask' => array( 'or' => 0b10100 ) ) ) ); +$c->update( [], [ '$bit' => [ 'bitmask' => [ 'or' => 0b10100 ] ] ] ); echo decbin( $c->findOne()['bitmask'] ), "\n"; // this is not in yet ;-) -$c->update( array(), array( '$bit' => array( 'bitmask' => array( 'xor' => 0b01110 ) ) ) ); +$c->update( [], [ '$bit' => [ 'bitmask' => [ 'xor' => 0b01110 ] ] ] ); echo decbin( $c->findOne()['bitmask'] ), "\n"; ?>]]></example> </slide> diff --git a/slides/mongodb/update.xml b/slides/mongodb/update.xml index bec578c..3206eee 100644 --- a/slides/mongodb/update.xml +++ b/slides/mongodb/update.xml @@ -6,14 +6,14 @@ $m = new MongoClient; $c = $m->demo->elephpants; $c->remove(); -$c->insert( array( '_id' => 'e42', 'name' => 'Kamubpo' ) ); -var_dump( $c->findOne( array( '_id' => 'e42' ) ) ); +$c->insert( [ '_id' => 'e42', 'name' => 'Kamubpo' ] ); +var_dump( $c->findOne( [ '_id' => 'e42' ] ) ); -$c->update( array( '_id' => 'e42' ), array( 'name' => 'Bo Tat' ) ); -var_dump( $c->findOne( array( '_id' => 'e42' ) ) ); +$c->update( [ '_id' => 'e42' ], [ 'name' => 'Bo Tat' ] ); +var_dump( $c->findOne( [ '_id' => 'e42' ] ) ); -$c->update( array( 'name' => 'Bo Tat' ), array( 'age' => '17' ) ); -var_dump( $c->findOne( array( '_id' => 'e42' ) ) ); +$c->update( [ 'name' => 'Bo Tat' ], [ 'age' => '17' ] ); +var_dump( $c->findOne( [ '_id' => 'e42' ] ) ); ?>]]></example> <blurb>update() replaces the document matching criteria entirely with a new object.</blurb> diff --git a/slides/mongodb/update2.xml b/slides/mongodb/update2.xml index dcacc5f..bf67d33 100644 --- a/slides/mongodb/update2.xml +++ b/slides/mongodb/update2.xml @@ -8,10 +8,10 @@ $m = new MongoClient; $c = $m->demo->elephpants; $c->drop(); -$c->insert( array( '_id' => 'e42', 'name' => 'Kamubpo', 'age' => 17 ) ); -$c->insert( array( '_id' => 'e43', 'name' => 'Denali', 'age' => 17 ) ); +$c->insert( [ '_id' => 'e42', 'name' => 'Kamubpo', 'age' => 17 ] ); +$c->insert( [ '_id' => 'e43', 'name' => 'Denali', 'age' => 17 ] ); -$c->update( array( 'age' => 17 ), array( '$inc' => array( 'age' => 1 ) ) ); +$c->update( [ 'age' => 17 ], [ '$inc' => [ 'age' => 1 ] ] ); var_dump( iterator_to_array( $c->find() ) ); ?>]]></example> diff --git a/slides/mongodb/upsert.xml b/slides/mongodb/upsert.xml index 701e1f4..bee2ceb 100644 --- a/slides/mongodb/upsert.xml +++ b/slides/mongodb/upsert.xml @@ -10,11 +10,11 @@ $c = $m->demo->elephpants; $c->drop(); function birthDay( $c, $name ) { $c->update( - array( 'name' => $name ), // criteria - array( '$inc' => array( 'age' => 1 ) ), // update spec - array( 'upsert' => true ) // options + [ 'name' => $name ], // criteria + [ '$inc' => [ 'age' => 1 ] ], // update spec + [ 'upsert' => true ] // options ); - echo $c->findOne( array( 'name' => 'Santon' ) )['age'], "\n"; + echo $c->findOne( [ 'name' => 'Santon' ] )['age'], "\n"; } birthDay( $c, 'Santon' ); diff --git a/slides/mongodb/write-import-script-result.xml b/slides/mongodb/write-import-script-result.xml index 08da078..11266e0 100644 --- a/slides/mongodb/write-import-script-result.xml +++ b/slides/mongodb/write-import-script-result.xml @@ -17,8 +17,8 @@ $d = $m->demo->poi; $d->drop(); // 3 ADD: Create an index on "name" and a "2d" index on "loc" -$d->ensureIndex( array( 'loc' => '2d' ) ); -$d->ensureIndex( array( 'name' => 1 ) ); +$d->ensureIndex( [ 'loc' => '2d' ] ); +$d->ensureIndex( [ 'name' => 1 ] ); var_dump($d->getIndexInfo()); ]]></example> diff --git a/slides/mongodb/write-import-script2.xml b/slides/mongodb/write-import-script2.xml index 4e97689..251b506 100644 --- a/slides/mongodb/write-import-script2.xml +++ b/slides/mongodb/write-import-script2.xml @@ -7,8 +7,8 @@ </list> <example><![CDATA[<?php // 1 ADD: Indexes for the tags -$d->ensureIndex( array( 'tags_indexed' => 1 ) ); -$d->ensureIndex( array( 'tags_indexed.k' => 1, 'tags_indexed.v' => 1 ) ); +$d->ensureIndex( [ 'tags_indexed' => 1 ] ); +$d->ensureIndex( [ 'tags_indexed.k' => 1, 'tags_indexed.v' => 1 ] ); var_dump($d->getIndexInfo()); ]]></example>