Nomad PHP talk

This commit is contained in:
Derick Rethans
2016-07-28 18:34:39 +01:00
parent 8590e339a6
commit 4d3d7fc7c9
12 changed files with 258 additions and 33 deletions

90
mongo-nomad16.xml Normal file
View File

@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<presentation css="10gen-strict.css">
<topic>MongoDB</topic>
<title>Grown-up MongoDB: Schema Design</title>
<event>Nomad PHP</event>
<location>Online</location>
<date>Jul 28th, 2016</date>
<speaker>Derick Rethans</speaker>
<email>derick@mongodb.com</email>
<twitter>derickr</twitter>
<url>http://derickrethans.nl/talks.html</url>
<joindin>https://joind.in/talk/cad90</joindin>
<slide>slides/mongodb/title.xml</slide>
<slide>slides/mongodb/me.xml</slide>
<slide>slides/mongodb/agenda-grownup.xml</slide>
** Terms **
<slide>slides/mongodb/collections-documents.xml</slide>
<slide>slides/mongodb/document-title.xml</slide>
<slide>slides/mongodb/document-simple.xml</slide>
<slide>slides/mongodb/document-complex.xml</slide>
<slide>slides/mongodb/collections-title.xml</slide>
<slide>slides/mongodb/collections.xml</slide>
<slide>slides/mongodb/index-title.xml</slide>
<slide>slides/mongodb/index.xml</slide>
** From PHP **
<slide>slides/mongodb/phplib-title.xml</slide>
<slide>slides/mongodb/phplib-intro.xml</slide>
<slide>slides/mongodb/phplib-crud.xml</slide>
<slide>slides/mongodb/phplib-index.xml</slide>
<slide>slides/mongodb/keys-title.xml</slide>
<slide>slides/mongodb/data-model.xml</slide>
Common Patterns
- RDBMS-normalisation.
<slide>slides/mongodb/eav.xml</slide>
<slide>slides/mongodb/eav2.xml</slide>
<slide>slides/mongodb/eav3.xml</slide>
<slide>slides/mongodb/dram-erd.xml</slide>
<slide>slides/mongodb/dram-erd-in-mongo.xml</slide>
<slide>slides/mongodb/whisky-words.xml</slide>
<slide>slides/mongodb/whisky-checking.xml</slide>
<slide>slides/mongodb/clinks.xml</slide>
<slide>slides/mongodb/clinks1.xml</slide>
<slide>slides/mongodb/clinks2.xml</slide>
<slide>slides/mongodb/clinks3.xml</slide>
<slide>slides/mongodb/clinks4.xml</slide>
<slide>slides/mongodb/clinks5.xml</slide>
<slide>slides/mongodb/document-validation.xml</slide>
<slide>slides/mongodb/embed-vs-link.xml</slide>
<slide>slides/mongodb/index-title.xml</slide>
<slide>slides/mongodb/indexes-new.xml</slide>
<slide>slides/mongodb/indexes-php.xml</slide>
<slide>slides/mongodb/indexes-explain-noindex.xml</slide>
<slide>slides/mongodb/indexes-explain2.xml</slide>
<slide>slides/mongodb/indexes-explain-index-sort.xml</slide>
<slide>slides/mongodb/indexes-explain3.xml</slide>
<slide>slides/mongodb/indexes-special.xml</slide>
<!-- MongoDB text search -->
<slide>slides/mongodb/text-create-index-php.xml</slide>
<slide>slides/mongodb/text-run-command.xml</slide>
<slide>slides/mongodb/text-index-options.xml</slide>
<slide>slides/mongodb/text-query-syntax.xml</slide>
<slide>slides/mongodb/recap-grownup.xml</slide>
<slide>slides/mongodb/questions.xml</slide>
<slide>slides/mongodb/mongodbeurope16.xml</slide>
<slide>slides/mongodb/resources.xml</slide>
</presentation>

View File

@@ -0,0 +1,10 @@
<slide>
<title>Agenda</title>
<list>
<bullet>Introduction</bullet>
<bullet>PHP &amp; MongoDB</bullet>
<bullet>Data Model</bullet>
<bullet>Indexes</bullet>
</list>
</slide>

View File

@@ -0,0 +1,31 @@
<slide>
<title>Explain (Sort)</title>
<example inline="1"><![CDATA[
> db.whisky.find( { name: 'Ord 10' } ).sort( *{ name: -1 }* ).explain();
{
"queryPlanner" : {
"namespace" : "dramio.whisky",
"indexFilterSet" : false,
"parsedQuery" : { "name" : { "$eq" : "Ord 10" } },
"winningPlan" : {
"stage" : "FETCH",
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"name" : 1
},
"indexName" : "name_1",
"isMultiKey" : false,
"direction" : *"backward"*,
"indexBounds" : {
"name" : [
"[\"Ord 10\", \"Ord 10\"]"
]
}
}
},
},
}
]]></example>
</slide>

View File

@@ -0,0 +1,24 @@
<slide>
<title>Explain (No Index)</title>
<example inline="1"><![CDATA[
> db.whisky.find( { distillery: 'Ord' } ).explain();
{
"queryPlanner" : {
"namespace" : *"dramio.whisky",*
"indexFilterSet" : false,
"parsedQuery" : { "distillery" : { "$eq" : "Ord" } },
"winningPlan" : {
"stage" : *"COLLSCAN",*
"filter" : {
"distillery" : {
*"$eq" : "Ord"*
}
},
"direction" : "forward"
},
*"rejectedPlans" : [ ]*
},
}
]]></example>
</slide>

View File

@@ -0,0 +1,32 @@
<slide>
<title>Explain (Covering Index)</title>
<example inline="1"><![CDATA[
> db.whisky.find( { name: 'Ord 10' }, { _id: 0, name: 1 } ).sort( { name: -1 } ).explain();
{
"queryPlanner" : {
"namespace" : "dramio.whisky",
"indexFilterSet" : false,
"parsedQuery" : { "name" : { "$eq" : "Ord 10" } },
"winningPlan" : {
*"stage" : "PROJECTION",*
"transformBy" : *{ "_id" : 0, "name" : 1 }*,
"inputStage" : {
*"stage" : "IXSCAN",*
"keyPattern" : {
"name" : 1
},
"indexName" : "name_1",
"isMultiKey" : false,
"direction" : "forward",
"indexBounds" : {
"name" : [
"[\"Ord 10\", \"Ord 10\"]"
]
}
}
},
},
}
]]></example>
</slide>

View File

@@ -8,7 +8,7 @@
<bullet>Indexes are just as important as in a relational database</bullet>
<bullet>Every collection has (automatically) an index on %_id%</bullet>
<bullet>Indexes can be: single field, compound key, on nested field names</bullet>
<bullet>MongoCursor->explain().</bullet>
<bullet>Indexes do add overhead</bullet>
</list>
</div>
</slide>

View File

@@ -7,18 +7,18 @@ db.checkins.createIndex( { 'clinked_by.slug': 1 } );
</example>
<blurb>Driver</blurb>
<example inline="1"><![CDATA[
<example inline="1"><![CDATA[&lt;?php
$cmd = new \MongoDB\Driver\Command( [
'createIndexes => 'checkins',
'indexes' => [
[ *'key'* => [ 'user_slug' => 1, 'friend_slug => 1 ], *'unique'* => true ],
]
] );
$manager->executeCommand( $cmd );
$manager->executeCommand( 'dramio', $cmd );
]]></example>
<blurb>Library</blurb>
<example inline="1"><![CDATA[
<example inline="1"><![CDATA[&lt;?php
require 'vendor/autoload.php';
$collection = (new MongoDB\Client)->dramio->user;
$collection->createIndex(

View File

@@ -0,0 +1,10 @@
<slide>
<title>Recap</title>
<list>
<bullet>Introduction</bullet>
<bullet>PHP &amp; MongoDB</bullet>
<bullet>Data Model</bullet>
<bullet>Indexes</bullet>
</list>
</slide>

View File

@@ -1,12 +1,27 @@
<slide>
<title>Create a Text Search Index</title>
<example><![CDATA[<?php
$m = new MongoClient;
<blurb>Driver</blurb>
<example inline="1"><![CDATA[&lt;?php
$cmd = new \MongoDB\Driver\Command( [
'createIndexes => 'articles',
'indexes' => [
[
'key' => [ 'subject' => *'text'*, 'post' => *'text'* ],
*'weights' => [ 'subject' => 10, 'post' => 5 ]*
]
]
] );
$manager->executeCommand( 'demo', $cmd );
?>]]></example>
$m->demo->articles->createIndex(
[ 'subject' => 'text', 'post' => 'text' ],
[ 'weights' => [ 'subject' => 10, 'post' => 5 ] ]
<blurb>Library</blurb>
<example inline="1"><![CDATA[&lt;?php
require 'vendor/autoload.php';
$collection = (new MongoDB\Client)->demo->articles;
$collection->createIndex(
[ 'subject' => *'text'*, 'post' => *'text'* ],
[ *'weights' => [ 'subject' => 10, 'post' => 5 ]* ]
);
?>]]></example>
</slide>

View File

@@ -4,30 +4,34 @@
<blurb>
Basic, default weights:
</blurb>
<example>
db.articles.createIndex( { subject: "text", post: "text" } );
<example inline="1">
$collection->createIndex( [ 'subject' => *'text'*, 'post' => *'text'* ] ),
</example>
<blurb>
Explicit weights:
</blurb>
<example>
db.articles.createIndex( { subject: "text", post: "text" },
{ weights: { "subject": 10 } } );
<example inline="1">
$collection->createIndex(
[ 'subject' => 'text', 'post' => 'text' ],
[ *'weights' => [ 'subject' => 10 ]* ]
);
</example>
<blurb>
Wildcard field: text at any depth, default weights:
</blurb>
<example>
db.articles.createIndex( { "$**": "text" } );
<example inline="1">
$collection->createIndex( [ *'$\*\*'* => 'text' ] ),
</example>
<blurb>
Wildcard field: override default weights and explicit weights:
Wildcard: override default weights and explicit weights:
</blurb>
<example>
db.articles.createIndex( { "$**": "text" },
{ weights: {"$**": 10, post: 5 } } );
<example inline="1">
$collection->createIndex(
[ '$\*\*' => 'text' ],
[ *'weights' => [ '$\*\*' => 10, 'post' => 5 ]* ]
);
</example>
</slide>

View File

@@ -1,7 +1,7 @@
<slide>
<title>Query Options and Sorting</title>
<example result="1"><![CDATA[<?php
<example result="0"><![CDATA[<?php
$m = new MongoClient;
$cursor = $m->demo->articles->find(

View File

@@ -1,25 +1,34 @@
<slide>
<title>Do a Text Search Query</title>
<div effect="fade-out">
<example>
db.articles.find(
{ '$text' : { '$search' : '"advent" "xdebug"' } },
{ subject: 1, _id: 0 }
);
</example>
</div>
<example inline="1"><![CDATA[&lt;?php
require 'vendor/autoload.php';
$m = new \MongoDB\Client;
<div effect="fade-in">
<example result="1"><![CDATA[<?php
$m = new MongoClient;
$cursor = $m->demo->articles->find(
[ '$text' => [ '$search' => '"advent" "xdebug"' ] ],
[ *'$text'* => [ '$search' => '"advent" "xdebug"' ] ],
[ 'subject' => 1, '_id' => 0 ]
);
foreach ( $cursor as $result ) {
echo $result['subject'], "\n";
}
?>]]></example>
<div effect="fade-in">
<blurb>Result:</blurb>
<example>
Contributing Advent 17: Printing stacks
Contributing Advent 22: Documenting changes
Contributing Advent 20: Xdebug halting on error
Contributing Advent 8: The magic __FILE__ constant
Contributing Advent 23: Reproducing issues
Whisky Advent: part 3
Whisky Advent: part 4
Contributing Advent 1: Xdebug and hidden properties
Contributing Advent 24: Wrapping up!
Contributing Advent
Contributing Advent 15: Xdebug connection timeout
</example>
</div>
</slide>