Mongo UG talk, and PHP Benelux tutorial.

This commit is contained in:
Derick Rethans
2013-01-23 21:03:57 +00:00
parent 8f2c5a4d35
commit e0a696e6c5
19 changed files with 493 additions and 10 deletions

63
mongo-osm-mug.xml Normal file
View File

@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<presentation css="10gen-strict.css">
<topic>Maps</topic>
<title>Store a city, a country or even a planet in your DB</title>
<event>MongoDB Meet-up #9</event>
<location>London, UK</location>
<date>November 26th, 2012</date>
<speaker>Derick Rethans</speaker>
<email>derick@10gen.com</email>
<twitter>derickr</twitter>
<joindin></joindin>
<slide>slides/map/title.xml</slide>
<!--
In this talk I will be explaining the strong points of OpenStreetMap and why
using GoogleMaps for your websites is generally a bad idea. Contrary to popular
belief, GoogleMaps isn't as amazing as it looks and they are a lot more evil
than they look. OpenStreetMap's data is also easily accessible for use in PHP
applications and the generated tiles can easily be embedded into a Web 2.0
application. Its open nature is a welcome and powerful geo database that can be
added to and used in whatever way imaginary.
-->
<!--
What is X?
-->
<slide>slides/map/osm-what.xml</slide>
<slide>slides/map/osm-data.xml</slide>
<slide>slides/map/osm-tags1.xml</slide>
<slide>slides/map/osm-tags2.xml</slide>
<slide>slides/map/osm-tags3.xml</slide>
<slide>slides/map/osm-tags4.xml</slide>
<slide>slides/map/osm-xapi.xml</slide>
<slide>slides/mongodb/osm-to-mongo-data.xml</slide>
<slide>slides/mongodb/osm-to-mongo-data2.xml</slide>
<slide>slides/mongodb/osm-to-mongo-data3.xml</slide>
<slide>slides/mongodb/osm-to-mongo-data4.xml</slide>
<slide>slides/mongodb/osm-schema1.xml</slide>
<slide>slides/mongodb/osm-schema2.xml</slide>
<slide>slides/mongodb/osm-schema3.xml</slide>
<slide>slides/map/finding-food-import-mongo2.xml</slide>
<slide>slides/map/import-script1.xml</slide>
<slide>slides/map/import-sizes1.xml</slide>
<slide>slides/map/import-script2.xml</slide>
<slide>slides/mongodb/idx-geo.xml</slide>
<slide>slides/mongodb/idx-geo2.xml</slide>
<slide>slides/mongodb/idx-geo3.xml</slide>
<slide>slides/map/find-mongo.xml</slide>
<slide>slides/map/finding-food-take2.xml</slide>
<slide>slides/map/mongo-country.xml</slide>
<slide>slides/mongodb/resources.xml</slide>
<slide>slides/mongodb/idx-geo-geohash.xml</slide>
<slide>slides/map/find-mongo2.xml</slide>
<slide>slides/map/find-mongo-html.xml</slide>
</presentation>

196
mongo-tut-phpbnl13.xml Normal file
View File

@@ -0,0 +1,196 @@
<?xml version="1.0" encoding="utf-8"?>
<presentation css="10gen-strict.css">
<topic>mongoDB</topic>
<title>Hands-On MongoDB</title>
<event>PHP Benelux 2013</event>
<location>Edegem, Belgium</location>
<date>Jan 25th, 2013</date>
<speaker>Derick Rethans</speaker>
<email>derick@10gen.com</email>
<twitter>derickr</twitter>
<url>http://derickrethans.nl/talks.html</url>
<joindin>http://joind.in/7779</joindin>
<slide>slides/mongodb/title.xml</slide>
<slide>slides/mongodb/me.xml</slide>
<slide>slides/mongodb/half-tutorial-topics.xml</slide>
<slide>slides/mongodb/section-intro.xml</slide>
<slide>slides/mongodb/databasefield.xml</slide>
<slide>slides/mongodb/collections-documents.xml</slide>
<slide>slides/mongodb/document.xml</slide>
<slide>slides/mongodb/connecting.xml</slide>
<slide>slides/mongodb/insert.xml</slide>
- single
<slide>slides/mongodb/id.xml</slide>
<slide>slides/mongodb/query.xml</slide>
<slide>slides/mongodb/query2.xml</slide>
- findOne
- find
<slide>slides/mongodb/query-advanced-ops.xml</slide>
<slide>slides/mongodb/cursors.xml</slide>
- cursor
<slide>slides/mongodb/limit-skip.xml</slide>
- limit/skip
<slide>slides/mongodb/update2a.xml</slide>
<!-- FIRST EXCERCISE -->
<slide>slides/mongodb/ex1-foursquare.xml</slide>
<slide>slides/map/osm-what.xml</slide>
<slide>slides/map/osm-data.xml</slide>
<slide>slides/map/osm-tags1.xml</slide>
<slide>slides/map/osm-tags2.xml</slide>
<slide>slides/map/osm-tags3.xml</slide>
<slide>slides/map/osm-tags4.xml</slide>
<slide>slides/mongodb/osm-to-mongo-data.xml</slide>
<slide>slides/mongodb/osm-to-mongo-data3.xml</slide>
<slide>slides/mongodb/osm-to-mongo-data4.xml</slide>
<slide>slides/mongodb/osm-schema3.xml</slide>
<slide>slides/map/import-script.xml</slide>
<slide>slides/map/import-script-exercise.xml</slide>
<slide>slides/map/query-exercise.xml</slide>
<slide>slides/map/query-exercise-checkin.xml</slide>
<slide>slides/mongodb/commands.xml</slide>
<slide>slides/mongodb/commands-aggregation.xml</slide>
<slide>slides/mongodb/aggregation-example-cuisine.xml</slide>
<slide>slides/mongodb/questions.xml</slide>
<!-- SCHEMA DESIGN -->
<slide>slides/mongodb/section-schema-design.xml</slide>
Common Patterns
- RDBMS-normalisation.
<slide>slides/mongodb/normalisation.xml</slide>
<slide>slides/mongodb/blog.xml</slide>
<slide>slides/mongodb/blog2.xml</slide>
<slide>slides/mongodb/considerations.xml</slide>
<slide>slides/mongodb/one-to-many1.xml</slide>
<slide>slides/mongodb/one-to-many2.xml</slide>
<slide>slides/mongodb/tip-array-key.xml</slide>
<slide>slides/mongodb/one-to-many3.xml</slide>
<slide>slides/mongodb/one-to-many4.xml</slide>
<slide>slides/mongodb/tip-paged-result.xml</slide>
<slide>slides/mongodb/many-to-many1.xml</slide>
<slide>slides/mongodb/many-to-many2.xml</slide>
<slide>slides/mongodb/many-to-many3.xml</slide>
<slide>slides/mongodb/embed-vs-link.xml</slide>
<slide>slides/map/update-exercise.xml</slide>
<slide>slides/mongodb/questions.xml</slide>
<!-- INDEXES -->
<slide>slides/mongodb/section-indexes.xml</slide>
<slide>slides/mongodb/idx-whats-in-store.xml</slide>
<slide>slides/mongodb/idx-startup-quotes.xml</slide>
<slide>slides/mongodb/idx-map.xml</slide>
<slide>slides/mongodb/idx-how-do-you-find-a-city.xml</slide>
<slide>slides/mongodb/idx-create.xml</slide>
<slide>slides/mongodb/idx-cities-by-name.xml</slide>
<slide>slides/mongodb/idx-how-do-you-find-a-large-city.xml</slide>
<slide>slides/mongodb/idx-cities-by-name-and-pop.xml</slide>
<slide>slides/mongodb/idx-cities-by-name-and-pop2.xml</slide>
<slide>slides/mongodb/idx-cities-by-name-and-pop3.xml</slide>
<slide>slides/mongodb/idx-how-do-you-find-a-large-city-on-a-mountain.xml</slide>
<slide>slides/mongodb/idx-cities-by-pop-and-dem.xml</slide>
<slide>slides/mongodb/idx-cities-by-pop-and-dem2.xml</slide>
<slide>slides/mongodb/idx-stored2.xml</slide>
<slide>slides/mongodb/idx-cities-by-pop-and-dem3.xml</slide>
<slide>slides/mongodb/idx-cities-by-pop-and-dem4.xml</slide>
<slide>slides/mongodb/idx-cities-by-pop-and-dem6.xml</slide>
<slide>slides/mongodb/idx-cities-by-pop-and-dem5.xml</slide>
<slide>slides/mongodb/idx-recap1.xml</slide>
<slide>slides/mongodb/idx-recap2.xml</slide>
<slide>slides/mongodb/idx-unique.xml</slide>
<slide>slides/mongodb/idx-covered.xml</slide>
<slide>slides/mongodb/idx-multi-key.xml</slide>
<slide>slides/mongodb/idx-which-one-is-picked.xml</slide>
<slide>slides/mongodb/idx-or.xml</slide>
<slide>slides/mongodb/idx-map2.xml</slide>
<slide>slides/mongodb/idx-geo.xml</slide>
<slide>slides/mongodb/idx-geo2.xml</slide>
<slide>slides/mongodb/idx-geo3.xml</slide>
<slide>slides/mongodb/idx-geo4.xml</slide>
unique
sparse
indexonly
multikey
2d
<slide>slides/mongodb/idx-recap3.xml</slide>
<slide>slides/mongodb/questions.xml</slide>
<!-- REPLICATION -->
<slide>slides/mongodb/section-replication.xml</slide>
<slide>slides/mongodb/repl-use-cases.xml</slide>
<slide>slides/mongodb/repl-types-of-outage.xml</slide>
<slide>slides/mongodb/repl-features.xml</slide>
<slide>slides/mongodb/repl-works-basic.xml</slide>
<slide>slides/mongodb/repl-works-normal.xml</slide>
<slide>slides/mongodb/repl-works-failover.xml</slide>
<slide>slides/mongodb/repl-oplog.xml</slide>
<slide>slides/mongodb/replication-setup.xml</slide>
<slide>slides/mongodb/repl-managing.xml</slide>
<slide>slides/mongodb/safe3.xml</slide>
<slide>slides/mongodb/repl-write-concern.xml</slide>
<slide>slides/mongodb/repl-tagging.xml</slide>
<slide>slides/mongodb/repl-tagging2.xml</slide>
<slide>slides/mongodb/repl-tagging-example.xml</slide>
<slide>slides/mongodb/read-preference2.xml</slide>
<slide>slides/mongodb/read-preference.xml</slide>
<slide>slides/mongodb/repl-eventual-consistency.xml</slide>
<slide>slides/mongodb/repl-features2.xml</slide>
<slide>slides/mongodb/repl-scenarios.xml</slide>
<slide>slides/mongodb/repl-set1.xml</slide>
<slide>slides/mongodb/repl-set2.xml</slide>
<slide>slides/mongodb/repl-set3.xml</slide>
<slide>slides/mongodb/repl-set4.xml</slide>
<slide>slides/mongodb/repl-set5.xml</slide>
<slide>slides/mongodb/repl-typical.xml</slide>
- setup
- slaveOk
- journal
- write concerns
<!-- SHARDING -->
<slide>slides/mongodb/section-sharding.xml</slide>
<slide>slides/mongodb/sharding.xml</slide>
<slide>slides/mongodb/sharding-key.xml</slide>
<slide>slides/mongodb/sharding-mongos.xml</slide>
<slide>slides/mongodb/sharding-config.xml</slide>
- mongos
- diagram
- transparent
<slide>slides/mongodb/questions.xml</slide>
<slide>slides/mongodb/resources.xml</slide>
</presentation>

View File

@@ -0,0 +1,26 @@
<slide>
<title>Exercise #1: The script</title>
<list>
<bullet>%git clone git://github.com/derickr/mongo-workshop.git%</bullet>
<bullet>%cd mongo-workshop &amp;&amp; git checkout import1%</bullet>
<bullet>Edit %import-data.php% to create the document structure at #1:
<list>
<bullet>Cast all values, due to SimpleXML weirdness</bullet>
<bullet>%_id% needs to be "n" + the node's ID (in
%$node['id']%)</bullet>
<bullet>Make sure to add the location (*lon*, *lat*) as a two
element array in the %loc% element.</bullet>
</list>
</bullet>
<bullet>Edit %import-data.php% to create the document structure at #3:
<list>
<bullet>%_id% needs to be "w" + the node's ID (in
%$way['id']%)</bullet>
</list>
</bullet>
<bullet>Add the %insert% statement at #2 and #4</bullet>
<bullet>Run the script: %php import-data.php compress.zlib://antwerp.xml.gz%</bullet>
</list>
</slide>

View File

@@ -0,0 +1,18 @@
<slide>
<title>The import script</title>
<list>
<bullet>Open file with XML Reader</bullet>
<bullet>Loop over all nodes, and:
<list>
<bullet>*Store the node in the database*</bullet>
</list>
</bullet>
<bullet>Loop over all the ways, and:
<list>
<bullet>*Look up locations for each node in the database*</bullet>
<bullet>Store the way into the database</bullet>
</list>
</bullet>
</list>
</slide>

View File

@@ -0,0 +1,14 @@
<slide>
<title>And now the planet?</title>
<list>
<bullet>*London*: 2m nodes, 0.75m ways, 0.13GB data, 0.19GB index: <br />fits easily in RAM</bullet>
<bullet>*UK*: 45m nodes, 10m ways, 5.6GB data, 8.6GB index:<br />fits just in RAM</bullet>
<bullet>*Planet*: 1500m nodes, 141m ways…</bullet>
</list>
<div effect="fade-in">
<blurb>
What do we do when we have 150GB of data and 230GB of indexes?
</blurb>
</div>
</slide>

View File

@@ -0,0 +1,23 @@
<slide>
<title>Exercise #3: Querying</title>
<list>
<bullet>Edit %functions.php% to create the query under #2</bullet>
<bullet>Hints:<list>
<bullet>We only need one result</bullet>
<bullet>The object ID that you need to query is stored in %$object%</bullet>
</list></bullet>
</list>
<div effect="fade-in">
<blurb>Expected, something like:</blurb>
<example>
$this->o = $this->c->findOne(
array(
'_id' => preg_replace( '/[^nw0-9]/', '', $object )
)
);
</example>
</div>
</slide>

View File

@@ -0,0 +1,20 @@
<slide>
<title>Exercise #2: Querying</title>
<list>
<bullet>Commit or stash your changes (%git stash%)</bullet>
<bullet>%git checkout web%</bullet>
<bullet>run: %php -S localhost:9002%</bullet>
<bullet>Browse to %http://localhost:9002%</bullet>
</list>
<div effect="fade-in">
<list>
<bullet>Edit %fetch-poi.php% to create the queries under #1a, #1b and #1c</bullet>
<bullet>Hints:<list>
<bullet>A pub is an *amenity*</bullet>
<bullet>You can define a regular expression with:<br/>%new MongoRegex( '/…/' );%</bullet>
</list></bullet>
</list>
</div>
</slide>

View File

@@ -0,0 +1,46 @@
<slide>
<title>Exercise #4: Updating</title>
<div effect="fade-out">
<list>
<bullet>Edit %functions.php% to create the update under #3</bullet>
<bullet>Things to keep in mind:<list>
<bullet>Where do you want to store the values?</bullet>
<bullet>Where are you storing the check-ins?</bullet>
<bullet>How often do we update?</bullet>
<bullet>How do we need to query the data in the future?</bullet>
</list></bullet>
</list>
</div>
<div effect="fade-in">
<blurb>Expected, something like:</blurb>
<example>
foreach( $values as $key => $value )
{
@$values[$key] = (string) $value;
if ( $values[$key] === '?' || $values[$key] === '' || $values[$key] === 'Array' )
{
continue;
}
if ( array_key_exists( $key, $this->tags ) )
{
if ( $values[$key] != $this->tags[$key] )
{
$updates["possible.$key"] = array( $values[$key], 0 );
}
}
else
{
$updates["possible.$key"] = array( $values[$key], 0 );
}
}
$update = array( '$addToSet' => $updates );
$this->d->poi->update( array( '_id' => $this->o['_id'] ), $update );
</example>
</div>
</slide>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

@@ -0,0 +1,58 @@
<slide>
<title>Aggregation example</title>
<div effect="fade-out">
<example>
> db.cities.find({ name: 'Atlanta' }).pretty();
{
"_id" : ObjectId("4fe82d3044670a8156004ca0"),
"geonameid" : 4180439,
"name" : "Atlanta",
"asciiname" : "Atlanta",
"alternatenames" : [
"ATL", "Atlanta", "Atlantae", "aeteullaenta", "arrlanra nagaram",
"atalanta", "atlanta", "atlanta", " jwrjya", "atoranta", "etalanta",
"etlanta", "ya te lan da", "Ατλάντα", "Атлантæ", "Атланта", "Ատլանտա",
"แอตแลนตา", "ཨ་ཊི་ལཱན་ཊཱ།", "အတ္တလန္တာမြို့", "ატლანტა", "アトランタ",
"亚特兰大", "애틀랜타"
],
"feature_class" : "P",
"feature_code" : "PPLA",
"country_code" : "US",
"admin1_code" : "GA",
"admin2_code" : "121",
"population" : 420003,
"elevation" : 320,
"dem" : 336,
"timezone" : "America/New_York",
"modification_date" : "2011-06-16",
"location" : [ -84.38798, 33.749 ]
}
</example>
</div>
<div effect="fade-in">
<example result="1"><![CDATA[<?php
$m = new MongoClient();
$c = $m->demo->cities;
$res = $c->aggregate( [
[ '$match' => [ 'name' => 'Atlanta' ] ],
[ '$unwind' => '$alternatenames' ],
[ '$project' => [
'name' => '$alternatenames',
'meta' => [
'elevation' => '$dem',
'population' => 1,
'timezone' => 1,
],
'location' => 1,
'_id' => 0,
] ],
[ '$sort' => [ 'name' => 1 ] ]
] );
var_dump( $res );
?>]]>
</example>
</div>
</slide>

BIN
slides/mongodb/bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@@ -0,0 +1,7 @@
<slide>
<title>Exercise #1</title>
<blurb class="big-centre">foursquare</blurb>
<image filename="foursquare.jpg"/>
</slide>

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

View File

@@ -0,0 +1,11 @@
<slide>
<title>Today's Topics</title>
<list>
<bullet>Introduction into MongoDB with PHP</bullet>
<bullet>Schema Design</bullet>
<bullet>Indexes</bullet>
<bullet>Practical Example of Schema Design and Indexes</bullet>
<bullet>Questions and Answers</bullet>
</list>
</slide>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

@@ -1,5 +1,5 @@
<slide>
<title>Importing OSM into MongoDB (3)</title>
<title>Importing OSM into MongoDB</title>
<div effect="fade-out">
<blurb>Find all pubs:</blurb>

View File

@@ -1,5 +1,5 @@
<slide>
<title>Importing OSM into MongoDB (4)</title>
<title>Importing OSM into MongoDB</title>
<example>
{

View File

@@ -10,9 +10,8 @@
$m = new MongoClient( 'mongodb://localhost:13000/?replSet=seta&w=2' );
$c = $m->demo->talks;
$c->insert(
array( '_id' => 'mongodb' ), // document
);
$c->insert( array( '_id' => 'mongodb' ) );
$c->insert( array( '_id' => 'mongodb' ) );
?>]]></example>
<list>

View File

@@ -1,10 +1,12 @@
<slide type="title">
<break lines="6"/>
<blurb class="event-title">:-:title:-:</blurb>
<blurb class="event-date">:-:event:-: - :-:location:-: - :-:date:-:</blurb>
<blurb class="event-presenter">Derick Rethans - :-:email:-: - twitter: @:-:twitter:-:</blurb>
<blurb class="pres-url-small">:-:joindin:-:</blurb>
<break lines="1"/>
<blurb class="event-presenter">Derick Rethans - :-:email:-:</blurb>
<blurb class="event-presenter">@:-:twitter:-:</blurb>
<blurb class="event-presenter">:-:joindin:-:</blurb>
<div class="footer">
<image align="left" filename="10gen.png" pdf-scale="0.4" x-offset="2" y-offset="12.3"/>
<image align="right" filename="mongodb.png" pdf-scale="0.4" x-offset="18" y-offset="13.3"/>
<image align="left" filename="10gen-small.png" pdf-scale="0.4" x-offset="2" y-offset="12.3"/>
<image align="right" filename="mongodb-small.png" pdf-scale="0.4" x-offset="18" y-offset="13.3"/>
</div>
</slide>