com presentations: Shell versions of some slides.: slides/mongodb/cursors-shell.xml slides/mongodb/finding-food-import-mongo-shell.xml
slides/mongodb/limit-skip-shell.xml slides/mongodb/update2a-shell.xml

From: Date: Mon, 17 Sep 2012 13:37:33 +0000
Subject: com presentations: Shell versions of some slides.: slides/mongodb/cursors-shell.xml slides/mongodb/finding-food-import-mongo-shell.xml
slides/mongodb/limit-skip-shell.xml slides/mongodb/update2a-shell.xml
Groups: php.pres 
Request: Send a blank email to pres+get-1840@lists.php.net to get a copy of this message
Commit: 056379cba8e8ceb6c2e92689637d507712f99a6d Author: Derick Rethans <github@derickrethans.nl> Mon, 17 Sep 2012 15:37:33 +0200 Parents: 6856935349717b3959e50380da80b97181b03940 Branches: master Link: http://git.php.net/?p=presentations.git;a=commitdiff;h=056379cba8e8ceb6c2e92689637d507712f99a6d Log: Shell versions of some slides. Changed paths: A slides/mongodb/cursors-shell.xml A slides/mongodb/finding-food-import-mongo-shell.xml A slides/mongodb/limit-skip-shell.xml A slides/mongodb/update2a-shell.xml Diff: diff --git a/slides/mongodb/cursors-shell.xml b/slides/mongodb/cursors-shell.xml new file mode 100644 index 0000000..cf7b2b2 --- /dev/null +++ b/slides/mongodb/cursors-shell.xml @@ -0,0 +1,15 @@ +<slide> +<title>Querying and looping</title> + +<blurb>Finding multiple documents is done with the %find()%, and returns an +iterator in the form of an iterator.</blurb> +<break/> + +<example result="0"><![CDATA[$ mongo +> use demo +switched to db demo +> db.talks.find( { 'talks.title' : { '$exists' : true } } ). +... forEach(function(a) { prin( a._id ) } ); +derickr +>]]></example> +</slide> diff --git a/slides/mongodb/finding-food-import-mongo-shell.xml b/slides/mongodb/finding-food-import-mongo-shell.xml new file mode 100644 index 0000000..9e45a4e --- /dev/null +++ b/slides/mongodb/finding-food-import-mongo-shell.xml @@ -0,0 +1,73 @@ +<slide> +<title>Think about the data schema!</title> + +<div effect="fade-out"> +<example> +use poi; +doc = { + 'name' : 'A440', + 'tags' : { + 'highway' : 'secondary', + 'oneway' : 'yes' + } +}; +db.poi.ensureIndex( { 'name' : 1 } ); +db.poi.ensureIndex( { 'tags.highway' : 1 } ); +db.poi.ensureIndex( { 'tags.oneway' : 1 } ); + +// Road with name=Strand +db.poi.find( { 'name' : 'Strand' } ); +// All roads +db.poi.find( { 'tags.highway' : { '$exists' : 1 } } ); +</example> +<list> + <bullet>Lots of indexed are required</bullet> + <bullet>Easy to extract data from</bullet> +</list> +</div> +<div effect="fade-in-out"> +<blurb>or:</blurb> +<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 +db.poi.find( { + 'tags' : { '$elemMatch' : { 'k' : 'name', 'v' : 'Strand' } } +} ); +// All roads +db.poi.find( { 'tags.k' : 'highway' } ); +</example> +<list> + <bullet>One index required</bullet> + <bullet>Good for finding key/value combinations</bullet> + <bullet>Extra index needed for "all roads" question (on %tags_indexed.k%)</bullet> +</list> +</div> +<div effect="fade-in"> +<blurb>or:</blurb> +<example>doc = { + 'tags' : { + 'name=A440', + 'highway=secondary', + 'oneway=yes' + } +); +db.poi.ensureIndex( { 'tags' : 1 } ); + +// Road with name=Strand +db.poi.find( { 'tags' : 'name=Strand' } ); +// All roads +db.poi.find( { 'tags' : /^highway=/ } );</example> +<list> + <bullet>One index required</bullet> + <bullet>Good for finding key/value combinations</bullet> + <bullet>Good enough for doing the "all roads" question</bullet> +</list> +</div> +</slide> diff --git a/slides/mongodb/limit-skip-shell.xml b/slides/mongodb/limit-skip-shell.xml new file mode 100644 index 0000000..908f7df --- /dev/null +++ b/slides/mongodb/limit-skip-shell.xml @@ -0,0 +1,19 @@ +<slide> +<title>Cursor methods</title> + +<example result="0"><![CDATA[use demo +c = db.cities.find( { 'country_code' : 'RU' } ). + sort( { 'name' : 1 } ). + limit( 5 ). + skip( 25 ). + forEach( function(a) { print( a.name ); } ); +]]></example> +Output: +<example> +Al’met’yevsk +Amursk +Anapa +Angarsk +Anna +</example> +</slide> diff --git a/slides/mongodb/update2a-shell.xml b/slides/mongodb/update2a-shell.xml new file mode 100644 index 0000000..1e24caa --- /dev/null +++ b/slides/mongodb/update2a-shell.xml @@ -0,0 +1,22 @@ +<slide> +<title>Updating documents</title> + +<blurb>Update only updates the *first* document it finds by default.</blurb> + +<blurb>You can set an option to get all matching documents to be updated</blurb> + +<example result="0"><![CDATA[<?php +use demo; +c = db.elephpants; +c.drop(); + +c.insert( { '_id' : 'e42', 'name' : 'Kamubpo', 'age' : 17 } ); +c.insert( { '_id' : 'e43', 'name' : 'Denali', 'age' : 17 } ); + +c.update( + { 'age' : 17 }, // criteria + { '$inc' : { 'age' : 1 } }, // update spec + { 'multiple' : true } // options: multiple +); +]]></example> +</slide>

« previous php.pres (#1840) next »