Permalink
Browse files

Map-Reduce fixes #6

  • Loading branch information...
1 parent 05a4742 commit 29aa3b914a7f2c91e698cabd1337543aa48e8536 @ericlemerdy committed Feb 27, 2012
Showing with 172 additions and 3 deletions.
  1. BIN 00_mongodb-logo.png
  2. BIN 08_badge-map-reduce.jpeg
  3. +95 −2 tutorial.html
  4. +77 −1 tutorial.txt
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -23,6 +23,9 @@ <h1 class="title">MongoDB</h1>
<div class="slide">
<h1>What's the plan ?</h1>
+<div class="figure">
+<img src="00_mongodb-logo.png" /><p class="caption"></p>
+</div>
<ol>
<li><p>MongoDB startup for developpers</p></li>
<li><p>Collection of documents != Relational tables</p>
@@ -678,7 +681,7 @@ <h1>Create an index</h1>
<h1>Achievement 3 : Master shell</h1>
<ul>
-<li><p>Second achievement :</p>
+<li><p>Third achievement :</p>
<p><img src="05_badge-shell.jpeg" alt="Be a shell master or the mastershell" /> Be a master shell !</p></li>
<li><p>Let's move on to java !</p></li>
</ul>
@@ -699,7 +702,7 @@ <h1>Maven project</h1>
<h1>Achievement 4 : Use mongoDB from java</h1>
<ul>
-<li><p>Second achievement :</p>
+<li><p>Fourth achievement :</p>
<p><img src="06_badge-java.jpeg" alt="Learn MongoDB in Java" /> You have learnt how to speak MongoDB in java !</p></li>
<li><p>Now, let's replicate</p></li>
</ul>
@@ -812,5 +815,95 @@ <h1>Simulate a network failure</h1>
<li><p>If there are enough node (a majority), there is a vote and a new primary is elected. In this case, the PRIMARY has been step down to SECONDARY. And the SECONDARY has been step up to PRIMARY. There can still have writings on database.</p></li>
</ul>
</div>
+
+<div class="slide">
+
+<h1>Achievement 5 : MongoDB never fails</h1>
+<ul>
+<li><p>Fifth achievement :</p>
+<p><img src="07_badge-fail-over.jpeg" alt="MongoDB never fails" /> MongoDB will never fail !</p></li>
+<li><p>Now, let's map reduce</p></li>
+</ul>
+</div>
+
+<div class="slide">
+
+<h1>Map/Reduce</h1>
+<ul>
+<li><p><a href="http://www.slideshare.net/nateabele/building-apps-with-mongodb">Source</a> from slide 25 to 29</p></li>
+<li><p>Define the map function:</p>
+<pre><code>&gt; var map = function() {
+ this.tags.forEach(function(t) {
+ emit(t, { count : 1 } );
+ });
+}
+</code></pre></li>
+</ul>
+</div>
+
+<div class="slide">
+
+<h1>Reduce</h1>
+<ul>
+<li><p>Define the reduce function:</p>
+<pre><code>&gt; var reduce = function(key, value) {
+ var count = 0;
+ for (var i = 0, len = value.length; i &lt; len; i++) {
+ count += value[i].count;
+ }
+ return { &quot;count&quot; : count };
+}
+</code></pre></li>
+</ul>
+</div>
+
+<div class="slide">
+
+<h1>Get the result</h1>
+<ul>
+<li><p>Get the result object</p>
+<pre><code>&gt; var result = db.cliparts.mapReduce(map, reduce, { out : &quot;mapreduceresult&quot; });
+&gt; result
+{
+ &quot;result&quot; : &quot;mapreduceresult&quot;,
+ &quot;timeMillis&quot; : 188,
+ &quot;counts&quot; : {
+ &quot;input&quot; : 2,
+ &quot;emit&quot; : 6,
+ &quot;reduce&quot; : 3,
+ &quot;output&quot; : 3
+ },
+ &quot;ok&quot; : 1,
+}
+</code></pre></li>
+<li><p>Reading the output collection:</p>
+<pre><code>&gt; db.mapreduceresult.find()
+{ &quot;_id&quot; : &quot;LAPTOP&quot;, &quot;value&quot; : { &quot;count&quot; : 2 } }
+{ &quot;_id&quot; : &quot;NOTEBOOK&quot;, &quot;value&quot; : { &quot;count&quot; : 2 } }
+{ &quot;_id&quot; : &quot;PC&quot;, &quot;value&quot; : { &quot;count&quot; : 2 } }
+</code></pre></li>
+</ul>
+</div>
+
+<div class="slide">
+
+<h1>Achievement 6 : Map/Reduce</h1>
+<ul>
+<li><p>Six achievement :</p>
+<p><img src="08_badge-map-reduce.jpeg" alt="MongoDB map reduce" /> MongoDB Map Reduce</p></li>
+</ul>
+</div>
+
+<div class="slide">
+
+<h1>Thank you</h1>
+<ul>
+<li><p>hu·mon·gous adj</p>
+<p>: extremely large : huge <a humongous building> <humongous amounts of money></p>
+<p>perhaps alteration of huge + monstrous</p>
+<p>First Known Use: circa 1967</p>
+<p><img src="02_badge-easy.jpeg" /> <img src="04_badge-nosql.jpeg" /> <img src="05_badge-shell.jpeg" /> <img src="06_badge-java.jpeg" /> <img src="07_badge-fail-over.jpeg" /> <img src="08_badge-map-reduce.jpeg" /></p></li>
+</ul>
+</div>
</body>
</html>
View
@@ -2,9 +2,12 @@
% Valtech *Cours du Soir*, Eric Le Merdy
% Feb 28, 2012
+
What's the plan ?
=================
+![](00_mongodb-logo.png)
+
#. MongoDB startup for developpers
#. Collection of documents != Relational tables
@@ -732,6 +735,79 @@ Achievement 5 : MongoDB never fails
- Fifth achievement :
- ![MongoDB never fails](06_badge-fail-over.jpeg) MongoDB will never fail !
+ ![MongoDB never fails](07_badge-fail-over.jpeg) MongoDB will never fail !
- Now, let's map reduce
+
+Map/Reduce
+==========
+
+ - [Source](http://www.slideshare.net/nateabele/building-apps-with-mongodb) from slide 25 to 29
+
+ - Define the map function:
+
+ > var map = function() {
+ this.tags.forEach(function(t) {
+ emit(t, { count : 1 } );
+ });
+ }
+
+Reduce
+======
+
+ - Define the reduce function:
+
+ > var reduce = function(key, value) {
+ var count = 0;
+ for (var i = 0, len = value.length; i < len; i++) {
+ count += value[i].count;
+ }
+ return { "count" : count };
+ }
+
+Get the result
+==============
+
+ - Get the result object
+
+ > var result = db.cliparts.mapReduce(map, reduce, { out : "mapreduceresult" });
+ > result
+ {
+ "result" : "mapreduceresult",
+ "timeMillis" : 188,
+ "counts" : {
+ "input" : 2,
+ "emit" : 6,
+ "reduce" : 3,
+ "output" : 3
+ },
+ "ok" : 1,
+ }
+
+ - Reading the output collection:
+
+ > db.mapreduceresult.find()
+ { "_id" : "LAPTOP", "value" : { "count" : 2 } }
+ { "_id" : "NOTEBOOK", "value" : { "count" : 2 } }
+ { "_id" : "PC", "value" : { "count" : 2 } }
+
+
+Achievement 6 : Map/Reduce
+==========================
+
+ - Six achievement :
+
+ ![MongoDB map reduce](08_badge-map-reduce.jpeg) MongoDB Map Reduce
+
+Thank you
+=========
+
+ - hu·mon·gous adj
+
+ : extremely large : huge <a humongous building> <humongous amounts of money>
+
+ perhaps alteration of huge + monstrous
+
+ First Known Use: circa 1967
+
+ ![](02_badge-easy.jpeg) ![](04_badge-nosql.jpeg) ![](05_badge-shell.jpeg) ![](06_badge-java.jpeg) ![](07_badge-fail-over.jpeg) ![](08_badge-map-reduce.jpeg)

0 comments on commit 29aa3b9

Please sign in to comment.