Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Some schema design principles fixes #2

  • Loading branch information...
commit 6f98c12867668dab70e0da373be5a2116a891b1c 1 parent 74ae476
@ericlemerdy authored
View
BIN  02_badge-easy.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  03_relational-schema.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  04_badge-nosql.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
179 tutorial.html
@@ -22,29 +22,33 @@ <h1 class="title">MongoDB</h1>
</div>
<div class="slide">
-<ul class="incremental">
-<li><p>Key messages:</p>
-<ul class="incremental">
-<li><p>MongoDB startup for developpers is easy</p></li>
+<h1>What's the plan ?</h1>
+<ol>
+<li><p>MongoDB startup for developpers</p></li>
<li><p>Collection of documents != Relational tables</p>
-<ul class="incremental">
+<ul>
<li>Database design and Indexes</li>
</ul></li>
-<li><p>Learn MongoDB query language is valuable and nothing more than Javascript</p></li>
+<li><p>Learn MongoDB query language</p></li>
<li><p>Java Driver basic usage</p></li>
-<li><p>Replication is easy and powerful</p></li>
-<li><p>Map/Reduce is possible</p></li>
-</ul></li>
-</ul>
+<li><p>Replication</p></li>
+<li><p>Map/Reduce</p></li>
+</ol>
+</div>
+
+<div class="slide">
+
+<h1>MongoDB startup</h1>
+<p><em>Have you ever installed Oracle ?</em></p>
</div>
<div class="slide">
<h1>Install the database</h1>
-<ul class="incremental">
+<ul>
<li><p>Visit the <a href="http://www.mongodb.org/downloads">Download page</a></p></li>
<li><p>Install the &quot;Production Release&quot;</p>
-<ul class="incremental">
+<ul>
<li>used 2.0.2 for this tutorial</li>
</ul></li>
</ul>
@@ -53,7 +57,7 @@ <h1 class="title">MongoDB</h1>
<div class="slide">
<h1>Run the database</h1>
-<ul class="incremental">
+<ul>
<li><p>MongoDB is essentially a database daemon :</p>
<pre><code>cd mongodb-linux-i686-2.0.2/bin
./mongod
@@ -79,7 +83,7 @@ <h1 class="title">MongoDB</h1>
<div class="slide">
<h1>Why it shutdown ?</h1>
-<ul class="incremental">
+<ul>
<li><p>In the logs:</p>
<pre><code>dbpath (/data/db/) does not exist, terminating
</code></pre></li>
@@ -90,11 +94,11 @@ <h1 class="title">MongoDB</h1>
<div class="slide">
<h1>Run the database on a specified path</h1>
-<ul class="incremental">
+<ul>
<li><p>Either</p>
-<ul class="incremental">
-<li><p>Create the '/data/db' default directory</p></li>
-<li><p>Or use the <code>dbpath</code> parameter:</p>
+<ul>
+<li><p>Create the <em>/data/db</em> default directory</p></li>
+<li><p>Or use the <em>dbpath</em> parameter:</p>
<pre><code>./mongod --help | grep &quot;\-\-dbpath&quot;
--dbpath arg directory for datafiles
</code></pre></li>
@@ -115,7 +119,7 @@ <h1 class="title">MongoDB</h1>
<div class="slide">
<h1>The Admin Web Console ?</h1>
-<ul class="incremental">
+<ul>
<li><p><a href="http://localhost:28017">http://localhost:28017</a></p>
<div class="figure">
<img src="01_admin-web-console.png" alt="the admin web console screenshot" /><p class="caption">the admin web console screenshot</p>
@@ -126,7 +130,7 @@ <h1 class="title">MongoDB</h1>
<div class="slide">
<h1>Does it work out-of-the-box ?</h1>
-<ul class="incremental">
+<ul>
<li><p>Click on <a href="http://localhost:28017/listDatabases?text=1">listDatabases</a></p>
<pre><code>REST is not enabled. use --rest to turn on.
check that port 28017 is secured for the network too.
@@ -138,9 +142,9 @@ <h1 class="title">MongoDB</h1>
<div class="slide">
<h1>Activate rest</h1>
-<ul class="incremental">
+<ul>
<li><p>Shutdown mongod</p></li>
-<li><p>Restart with <code>--rest</code> option:</p>
+<li><p>Restart with <em>--rest</em> option:</p>
<pre><code>./mongod --dbpath ../../mongodatadb --rest
</code></pre></li>
<li><p>Option has been passed:</p>
@@ -164,17 +168,17 @@ <h1 class="title">MongoDB</h1>
{ &quot;JSON&quot; : &quot;rocks&quot; } }
}
</code></pre>
-<ul class="incremental">
+<ul>
<li><p>MongoDB Admin Web Console uses the rest extension to easily display the results of commands</p></li>
<li><p>BSON is the binary encoded version of JSON</p></li>
-<li><p>BSON is first class citizen in MongoDB</p></li>
+<li><p>JSON is first class citizen in MongoDB</p></li>
</ul>
</div>
<div class="slide">
<h1>It is time to open a MongoDB shell !</h1>
-<ul class="incremental">
+<ul>
<li><p>Practice first, how to start a mongo client:</p>
<pre><code>./mongo
</code></pre></li>
@@ -184,9 +188,9 @@ <h1 class="title">MongoDB</h1>
&gt;
</code></pre></li>
<li><p>This has worked because</p>
-<ul class="incremental">
-<li><p>You started 'mongod' on the default <em>27017</em> port</p></li>
-<li><p>'mongo' connects on a database named 'test' by default</p></li>
+<ul>
+<li><p>You started <em>mongod</em> on the default <em>27017</em> port</p></li>
+<li><p><em>mongo</em> connects on a database named <em>test</em> by default</p></li>
</ul></li>
</ul>
</div>
@@ -196,7 +200,7 @@ <h1 class="title">MongoDB</h1>
<h1>Help</h1>
<pre><code>&gt; help
</code></pre>
-<ul class="incremental">
+<ul>
<li><p>Returns</p>
<pre><code>db.help() help on db methods
db.mycoll.help() help on collection methods
@@ -225,8 +229,17 @@ <h1 class="title">MongoDB</h1>
<div class="slide">
+<h1>First Achievement : MongoDB startup</h1>
+<ul>
+<li><p>First achievement :</p>
+<p><img src="02_badge-easy.jpeg" alt="MongoDB startup is easy" /> MongoDB startup for developpers is easy !</p></li>
+</ul>
+</div>
+
+<div class="slide">
+
<h1>Data breakdown structure</h1>
-<ul class="incremental">
+<ul>
<li><p>Document &lt; Collection &lt; Database &lt; Runtime</p></li>
<li><p>Document : JSON fragment</p>
<p>ex:</p>
@@ -247,33 +260,27 @@ <h1 class="title">MongoDB</h1>
<div class="slide">
-<h1>Are you empty ?</h1>
-<ul class="incremental">
-<li><p>Connect to a database</p>
-<pre><code>&gt; use test
-switched to db test
+<h1>JSON</h1>
+<ul>
+<li><p>Object</p>
+<pre><code>{ pairs }
</code></pre></li>
-<li><p>Find the collections of the database</p>
-<pre><code>&gt; db.getCollectionNames()
-[ ]
+<li><p>Pair</p>
+<pre><code>string : Value
+</code></pre></li>
+<li><p>Value</p>
+<pre><code>Array, primitive values
+</code></pre></li>
+<li><p>Array</p>
+<pre><code>[ Values ]
</code></pre></li>
-<li><p>The collection is empty !</p></li>
-</ul>
-</div>
-
-<div class="slide">
-
-<h1>Insert a doc... Wait a minute...</h1>
-<ul class="incremental">
-<li><p>First achievement :</p>
-<p>MongoDB startup for developpers is easy.</p></li>
</ul>
</div>
<div class="slide">
-<h1>Overview of a document</h1>
-<ul class="incremental">
+<h1>Sample document</h1>
+<ul>
<li><p>A JSON document :</p>
<pre><code>&gt; clipart = {
&quot;title&quot; : &quot;Code Story logo&quot;,
@@ -297,43 +304,61 @@ <h1 class="title">MongoDB</h1>
<div class="slide">
-<h1>Create a collection</h1>
-<ul class="incremental">
-<li><p>Let's create the 'cliparts' collection.</p></li>
-<li><p>There is nothing to do as long you do not insert to a first document in it :</p>
-<pre><code>&gt; db.cliparts.findOne()
-null
-</code></pre></li>
-<li><p>Does a read has created the collection ?</p>
-<pre><code>&gt; db.getCollectionNames()
-[ ]
-</code></pre>
-<p>Obviously no</p></li>
+<h1>Relational schema</h1>
+<ul>
+<li><div class="figure">
+<img src="03_relational-schema.png" title="Relational schema" /><p class="caption"></p>
+</div>
+<p>http://yuml.me/diagram/scruffy/class/[Clipart|title : String;drawn-by : String;created : Date;description : String;tags : List<String>;viewed-by : Integer], [User|name : String;href : Url], [Image|svg : Url;png : Url],[Clipart]&lt;&gt;*-uploader 1&gt;[User], [Clipart]&lt;&gt;1-image 1&gt;[Image]</p></li>
</ul>
</div>
<div class="slide">
-<h1>Insert the document in the collection</h1>
-<pre><code>&gt; db.cliparts.save(clipart)
-</code></pre>
-<ul class="incremental">
-<li><p>Does a write has created the collection ?</p>
-<pre><code>&gt; db.getCollectionNames()
-[ &quot;cliparts&quot;, &quot;system.indexes&quot; ]
-</code></pre>
-<p>Obviously yes</p>
-Even 2 collections !
-<ul class="incremental">
-<li>cliparts : the collection that contains our new document</li>
-<li>system.indexes : the index to allow mongo to be fast searching</li>
-</ul></li>
+<h1>I ♥ SQL</h1>
+<ul>
+<li><p>MongoDB is <strong>NOT</strong> a relational database</p></li>
+<li><p>Forget what you learn about normalisation</p>
+<p>This just not apply to what mongodb can do</p></li>
+<li><p>In relational model, there is a promise : &quot;You can decouple schema design from applicative work (thanks to normalization)&quot;</p>
+<p>That's why we get RDBMs specialists after all...</p></li>
+<li><p>In MongoDB, you have to design your documents <strong>for the job</strong> that your application must do.</p></li>
+</ul>
+</div>
+
+<div class="slide">
+
+<h1>Document based schema design principles</h1>
+<ul>
+<li><p>Transaction is only <strong>document-based</strong></p></li>
+<li><p>Storage is cheap</p></li>
+<li><p><strong>Do not</strong> perform runtime relations</p>
+<p><strong>Duplicate</strong> !</p>
+<p>E.g. : Clipart -&gt; User</p></li>
+<li><p>Think of consequences in your application :</p>
+<p>When a user change its display name...</p></li>
+<li><p>Does not apply to all domains where A(tomicity), C(onsistency), I(solation), D(urability) is appreciated through the entire schema.</p></li>
</ul>
</div>
<div class="slide">
-<h1>Digging in indexes</h1>
+<h1>Schema free ?</h1>
+<ul>
+<li><p>A single collection can store different &quot;types&quot; of documents</p></li>
+<li><p>Manage the schema evolution by your application</p>
+<p>Evolving data structure when accessing the document for exemple</p></li>
+</ul>
+</div>
+
+<div class="slide">
+
+<h1>Achievement 2 : Document schema design principles</h1>
+<ul>
+<li><p>Second achievement :</p>
+<p><img src="04_badge-nosql.jpeg" alt="NoSQL document database != relationnal" /> Document oriented schema design is different from relational !</p></li>
+<li><p>More informations : <a href="http://www.10gen.com/presentations/mongosv-2011/schema-design-principles-and-practice">10gen - MongoDB Presentations - Schema Design Principles and Practice</a></p></li>
+</ul>
</div>
</body>
</html>
View
137 tutorial.txt
@@ -2,21 +2,27 @@
% Valtech *Cours du Soir*, Eric Le Merdy
% Feb 28, 2012
- - Key messages:
+What's the plan ?
+=================
+
+ #. MongoDB startup for developpers
- - MongoDB startup for developpers is easy
+ #. Collection of documents != Relational tables
- - Collection of documents != Relational tables
+ + Database design and Indexes
- - Database design and Indexes
+ #. Learn MongoDB query language
- - Learn MongoDB query language is valuable and nothing more than Javascript
+ #. Java Driver basic usage
- - Java Driver basic usage
+ #. Replication
- - Replication is easy and powerful
+ #. Map/Reduce
+
+MongoDB startup
+===============
- - Map/Reduce is possible
+_Have you ever installed Oracle ?_
Install the database
====================
@@ -65,9 +71,9 @@ Run the database on a specified path
- Either
- - Create the '/data/db' default directory
+ - Create the _/data/db_ default directory
- - Or use the `dbpath` parameter:
+ - Or use the _dbpath_ parameter:
./mongod --help | grep "\-\-dbpath"
--dbpath arg directory for datafiles
@@ -106,7 +112,7 @@ Activate rest
- Shutdown mongod
- - Restart with `--rest` option:
+ - Restart with _--rest_ option:
./mongod --dbpath ../../mongodatadb --rest
@@ -134,7 +140,7 @@ Why JSON ?
- BSON is the binary encoded version of JSON
- - BSON is first class citizen in MongoDB
+ - JSON is first class citizen in MongoDB
It is time to open a MongoDB shell !
====================================
@@ -151,9 +157,9 @@ It is time to open a MongoDB shell !
- This has worked because
- - You started 'mongod' on the default *27017* port
+ - You started _mongod_ on the default _27017_ port
- - 'mongo' connects on a database named 'test' by default
+ - _mongo_ connects on a database named _test_ by default
Help
====
@@ -184,6 +190,13 @@ Help
DBQuery.shellBatchSize = x set default number of items to display on shell
exit quit the mongo shell
+First Achievement : MongoDB startup
+===================================
+
+ - First achievement :
+
+ ![MongoDB startup is easy](02_badge-easy.jpeg) MongoDB startup for developpers is easy !
+
Data breakdown structure
========================
@@ -208,30 +221,27 @@ Data breakdown structure
- Runtime (daemon) : several Databases (physically stored in the dbpath)
-Are you empty ?
-===============
+JSON
+====
- - Connect to a database
+ - Object
- > use test
- switched to db test
+ { pairs }
- - Find the collections of the database
+ - Pair
- > db.getCollectionNames()
- [ ]
+ string : Value
- - The collection is empty !
+ - Value
-Insert a doc... Wait a minute...
-================================
+ Array, primitive values
- - First achievement :
+ - Array
- MongoDB startup for developpers is easy.
+ [ Values ]
-Overview of a document
-======================
+Sample document
+===============
- A JSON document :
@@ -252,38 +262,63 @@ Overview of a document
}
}
-Create a collection
-===================
+Relational schema
+==================
- - Let's create the 'cliparts' collection.
+ - ![](03_relational-schema.png "Relational schema")
+
+ http://yuml.me/diagram/scruffy/class/[Clipart|title : String;drawn-by : String;created : Date;description : String;tags : List<String>;viewed-by : Integer], [User|name : String;href : Url], [Image|svg : Url;png : Url],[Clipart]<>*-uploader 1>[User], [Clipart]<>1-image 1>[Image]
- - There is nothing to do as long you do not insert to a first document in it :
+I ♥ SQL
+========
- > db.cliparts.findOne()
- null
+ - MongoDB is __NOT__ a relational database
- - Does a read has created the collection ?
+ - Forget what you learn about normalisation
- > db.getCollectionNames()
- [ ]
+ This just not apply to what mongodb can do
- Obviously no
-Insert the document in the collection
-=====================================
+ - In relational model, there is a promise : "You can decouple schema design from applicative work (thanks to normalization)"
- > db.cliparts.save(clipart)
+ That's why we get RDBMs specialists after all...
- - Does a write has created the collection ?
+ - In MongoDB, you have to design your documents __for the job__ that your application must do.
- > db.getCollectionNames()
- [ "cliparts", "system.indexes" ]
+Document based schema design principles
+=======================================
- Obviously yes
+ - Transaction is only __document-based__
- Even 2 collections !
- - cliparts : the collection that contains our new document
- - system.indexes : the index to allow mongo to be fast searching
+ - Storage is cheap
-Digging in indexes
-==================
+ - __Do not__ perform runtime relations
+
+ __Duplicate__ !
+
+ E.g. : Clipart -> User
+
+ - Think of consequences in your application :
+
+ When a user change its display name...
+
+ - Does not apply to all domains where A(tomicity), C(onsistency), I(solation), D(urability) is appreciated through the entire schema.
+
+Schema free ?
+=============
+
+ - A single collection can store different "types" of documents
+
+ - Manage the schema evolution by your application
+
+ Evolving data structure when accessing the document for exemple
+
+
+Achievement 2 : Document schema design principles
+=================================================
+
+ - Second achievement :
+
+ ![NoSQL document database != relationnal](04_badge-nosql.jpeg) Document oriented schema design is different from relational !
+
+ - More informations : [10gen - MongoDB Presentations - Schema Design Principles and Practice](http://www.10gen.com/presentations/mongosv-2011/schema-design-principles-and-practice)
Please sign in to comment.
Something went wrong with that request. Please try again.