<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>theChrisWalker.net &#187; MongoDB</title>
	<atom:link href="http://thechriswalker.net/tag/mongodb/feed" rel="self" type="application/rss+xml" />
	<link>http://thechriswalker.net</link>
	<description>I like Web Development</description>
	<lastBuildDate>Tue, 31 Aug 2010 07:42:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>VPS Migration for thechriswalker.net &#8211; New Host, New OS, no Plesk</title>
		<link>http://thechriswalker.net/2010-03/vps-migration-for-thechriswalker-net-new-host-new-os-no-plesk.html</link>
		<comments>http://thechriswalker.net/2010-03/vps-migration-for-thechriswalker-net-new-host-new-os-no-plesk.html#comments</comments>
		<pubDate>Thu, 25 Mar 2010 19:16:21 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Not Code]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Server Administration]]></category>

		<guid isPermaLink="false">http://thechriswalker.net/?p=198</guid>
		<description><![CDATA[Not that I didn&#8217;t like Plesk. I just have the urge to understand things well, and I couldn&#8217;t understand all of how Plesk worked&#8230; So I wanted it &#8220;all-manual&#8221;, like the true hardcore (read: idiot) I am. I had been using a VPS to host this website (amongst other things) and it was getting old. [...]]]></description>
			<content:encoded><![CDATA[<p>Not that I didn&#8217;t like Plesk. I just have the urge to understand things well, and I couldn&#8217;t understand all of how Plesk worked&#8230; So I wanted it &#8220;all-manual&#8221;, like the true hardcore (read: <em>idiot</em>) I am.</p>
<p>I had been using a VPS to host this website (amongst other things) and it was getting old. It ran on CentOS 4 and used Plesk as a control panel. PHP was down at version 4.2.2 or something and MySQL still at version 4.x. I didn&#8217;t understand server administration as well as I do now and the whole thing was a bit of a mess. So I decided a fresh start, with a VPS on more powerful hardware and built cleanly.</p>
<p>So I went for a basic VPS from <a href="http://www.34sp.com">34SP.com</a> with no control panel and using Ubuntu 9.04 as the OS. They set up the server quickly and so I went about configuring it how I wanted. There were a couple of snags along the road and so I&#8217;ll tell you about them here too.</p>
<p><span id="more-198"></span></p>
<h2>The Basics, disabling root.</h2>
<p>First things first, the VPS came with the root account enabled and that as the only user on the system. Now I like to have my root account disabled and use sudo, so I created an admin user, granted sudo rights and disabled the root account. The command used are below.</p>
<p>Create user and set password:</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># useradd admin</span><br />
<span style="color: #666666; font-style: italic;"># passwd admin</span><br />
<span style="color: #666666; font-style: italic;"># visudo</span></div></div>
<p>Now in the sudoer&#8217;s file you&#8217;ll see a line for root which looks something like:</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">root ALL=(ALL) ALL</div></div>
<p>duplicate this line but with you&#8217;re username:</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">admin ALL=(ALL) ALL</div></div>
<p>save and exit. Now log out of <tt>root</tt> and back in as <tt>admin</tt>, then disable the root account:</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">passwd</span> <span style="color: #660033;">-l</span> root</div></div>
<p>and we&#8217;re done!. Now on this system my home directory wasn&#8217;t created (probably because I didn&#8217;t give the right flags in the <tt>useradd</tt> command. So we need to make it.</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>admin</div></div>
<h2>LAMP Stack</h2>
<p>34SP had installed Apache but not PHP or MySQL, both of which I wanted. In fact I wanted the following:</p>
<ul>
<li> Apache with mod_rewrite</li>
<li> PHP5.3+ (5.3 is important to me) with APC, Xdebug and MongoDB</li>
<li> MongoDB server </li>
<li> MySQL5 server </li>
</ul>
<p>I also needed to migrate my blog from it&#8217;s current location, to the new server. The Blog uses WordPress 2.8.something and the latest version at time of writing is 2.9.2 (time to upgrade!). WordPress doesn&#8217;t mention PHP5.3 support so this could be fun.</p>
<p>So, first hurdle, the default Ubuntu Repositories do not have packages for PHP5.3. This leaves 2 options, compile from source or find a repositiory which does have the packages. Knowing which I&#8217;d prefer and having already heard of dotdeb.org I added the dotdeb.org PHP5.3 repository to my <tt>sources.list</tt> and then I could install PHP5.3.2 and xdebug and apc right from <tt>apt</tt>!</p>
<p>After editing <tt>/etc/apt/sources.list</tt>:</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> update<br />
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5 php5-mysql php5-cli php5-xdebug php5-apc mysql5-server</div></div>
<p>But I also wanted MongoDB which is only available as a PECL module. So I need the <tt>php5-dev</tt> package. unfortunately, this gave me an error about <tt>libtool</tt> not being the correct version. and the only way to resolve it (that I could find) was to use libtool from the previous Ubuntu release.</p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> purge libtool<br />
$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>cn.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>hardy<span style="color: #000000; font-weight: bold;">/</span>libtool.deb<br />
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-i</span> libtool.deb<br />
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> php5-dev</div></div>
<p>Then it worked like a dream and I could finally use <tt>pecl</tt></p>
<div class="codecolorer-container bash mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> pecl <span style="color: #c20cb9; font-weight: bold;">install</span> mongo</div></div>
<p>That was the PHP module, but what about the actual MongoDB server itself? Well, there&#8217;s a repository for that as well. Add it to your sources.list, update then you can <tt>apt-get install mongodb</tt>. no configuration necessary. The phpinfo() output shows the mongo extension installed correctly and the mongo shell functions to show the mongodb server is working fine.</p>
<p>OK, now time to get my blog up and running, so I create a new virtual host in <tt>/etc/apache2/sites-available</tt> and use the apache tool to enable it <tt>sudo a2ensite thechriswalker.net</tt>. I have all my virtual hosts in <tt>/var/www/vhost/<domain>/{httpdocs,logs}</tt>, I change to the httpdocs directory and grab wordpress <tt> wget http://wordpress.org/latest.tar.gz</tt>, unzip and browse to it to see if it worked!</p>
<p>Well, of course it didn&#8217;t &#8211; I hadn&#8217;t done a couple of things. First I needed to restart Apache to enable the Virtual Host I had created. Then I realised that the DNS hadn&#8217;t propagated so I needed to set a static <tt>hosts</tt> entry on my local computer. This done I tried again &#8211; success!</p>
<p>So I dumped the database from the old VPS, copied (scp&#8217;d) my custom theme, plugins and some other non-wordpress content across to the new one. On the new one, I imported the wordpress database and tried to access it again. It took me through a 2 step &#8220;we need to update your database&#8221; (it was 2.8 not 2.9 remember) screen which worked great! That was easier than expected and I haven&#8217;t seen anything behave oddly under PHP5.3 &#8211; result.</p>
<h2>More</h2>
<p>Now I just need to setup the email side of things, I want to be able to send and recieve mail securely through this server, but thats a job for another day&#8230; Also I moved the email for this domain over to Google Apps, as I like GMail so much, so I may not even bother with the email part of this!</p>
]]></content:encoded>
			<wfw:commentRss>http://thechriswalker.net/2010-03/vps-migration-for-thechriswalker-net-new-host-new-os-no-plesk.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mongo &#8212; and the coolness of Document-Oriented Databases</title>
		<link>http://thechriswalker.net/2010-03/mongo-and-the-coolness-of-document-oriented-databases.html</link>
		<comments>http://thechriswalker.net/2010-03/mongo-and-the-coolness-of-document-oriented-databases.html#comments</comments>
		<pubDate>Tue, 09 Mar 2010 21:44:22 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[MongoDB]]></category>
		<category><![CDATA[Rapid Application Development]]></category>

		<guid isPermaLink="false">http://thechriswalker.net/?p=173</guid>
		<description><![CDATA[I have been following a PHP Rapid Application Development Framework called Lithium with much interest (for other reasons which I fully intend to blog about later) and they are the ones I owe for turning me on to document oriented database systems. So what are they and why are they so cool, and what/who the [...]]]></description>
			<content:encoded><![CDATA[<p>I have been following a PHP Rapid Application Development Framework called <a href="http://lithify.me" title="The Most RAD PHP Framework: Lithium">Lithium</a> with much interest (for other reasons which I fully intend to blog about later) and they are the ones I owe for turning me on to document oriented database systems. </p>
<p>So what are they and why are they so cool, and what/who the hell is &#8220;Mongo&#8221;?</p>
<p>Let&#8217;s deal with the what first. &#8220;Traditional&#8221; database systems are Relational, they are characterised by strictly defined tables, strong relations between tables and their <a href="http://wikipedia.org/wiki/ACID" title="ACID on Wikipedia">ACID</a> compliance. It simple terms that means you say: </p>
<p><em>&#8220;I want a table of users and each one <strong>will</strong> have a first name, a last name and an email address, and each of those <strong>will</strong> be a &#8216;text&#8217; entry of a maximum of 255 characters&#8221;</em>.</p>
<p>If at a later date you want to add more info, then you have to go back and alter your table definition, give the old rows default values and fix any coding bugs that relied on the previous structure (not that you&#8217;d ever develop such a dependant application). Now the approach in a document oriented database is that you say:</p>
<p><em>&#8220;I want a table of users&#8221;</em></p>
<p>Then you can give each one whatever data you want. you may have one user with a name and address, another with a name and phone number only, a third might have a phone number and address but no first name. All these records can co-exist! That&#8217;s pretty different and I really didn&#8217;t know whether it was a good idea. So I played with <a href="http://mogodb.org/" title="MongoDB homepage">MongoDB</a>.</p>
<p><span id="more-173"></span></p>
<p>MongoDB is really cool. I installed it my laptop simply and fired up the shell to play. The syntax is very javascript-like, becasue it <em>is</em> javascript! So we can do this.</p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">MongoDB shell version<span style="color: #339933;">:</span> 1.3.3<span style="color: #339933;">-</span><br />
url<span style="color: #339933;">:</span> test<br />
connecting to<span style="color: #339933;">:</span> test<br />
type <span style="color: #3366CC;">&quot;help&quot;</span> <span style="color: #000066; font-weight: bold;">for</span> help<br />
<span style="color: #339933;">&gt;</span> db.<span style="color: #660066;">myFirstMongoDB</span>.<span style="color: #660066;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>key<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">,</span> mixed<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">&quot;one&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;two&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;three&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> deep<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>has<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>another<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><br />
ObjectId<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;4b96b836ea70a136feb89c20&quot;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #339933;">&gt;</span> db.<span style="color: #660066;">myFirstMongoDB</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;_id&quot;</span> <span style="color: #339933;">:</span> ObjectId<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;4b96b836ea70a136feb89c20&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;key&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">,</span> &nbsp;<span style="color: #3366CC;">&quot;mixed&quot;</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span> <span style="color: #3366CC;">&quot;one&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;two&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;three&quot;</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <br />
&nbsp; &nbsp;<span style="color: #3366CC;">&quot;deep&quot;</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;has&quot;</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;another&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;object&quot;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span><br />
<span style="color: #339933;">&gt;</span></div></div>
<p>Notice two amazing things here.</p>
<ol>
<li>We never created the table! we simply call <tt>db.myFirstMongoDB...</tt> which creates the &#8220;collection&#8221; (as they are called in the document oriented world). We certainly never defined a schema!</li>
<li>We passed an object with nested data. Not just simple fields! We can use this in a much more useful way in the next example</li>
</ol>
<p>So why might you want to do this. Consider a website with articles. Articles are written by a person, they are published on a date and the have content, tags, comments, view counts, trackbacks, and a proprietary rating system. If this where a relational database, we are looking at the following tables:</p>
<div class="codecolorer-container text mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">articles: holds the article, date, person_id, view counts, proprietary rating<br />
people: holds the writers<br />
comments: the comments, related by article_id<br />
trackbacks: link back details<br />
ratings: the info for the proprietary system.<br />
tags: tag info<br />
tags_articles: a join table linking tags to the articles</div></div>
<p>Joining all that info together is not only complex, but can be a fair amount of load on the system. As more info wants to be added by the website owners changes become more complicated and difficult. However with Mongo I can hold the article in one collection like this:</p>
<p>[</p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#123;</span> <br />
&nbsp; <span style="color: #3366CC;">&quot;published&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;2010-03-09 21:21:00&quot;</span><span style="color: #339933;">,</span> <br />
&nbsp; <span style="color: #3366CC;">&quot;author&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;name&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Chris Walker&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;profile&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;/profiles/chris-walker&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">&quot;title&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;My amazing Article&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">&quot;content&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;here's the text...&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">&quot;tags&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span> <span style="color: #3366CC;">&quot;wonder&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;amazement&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;mongo&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;demo&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;chris&quot;</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #3366CC;">&quot;comments&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;commenter&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Rosie&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;comment&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;What is this?&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;when&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;2010-03-09 22:02:00&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;commenter&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Chris&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;url&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://thechriswalker.net/&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;comment&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;it's class, that's what!&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;when&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;2010-03-09 23:12:00&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;commenter&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;anonymous&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;comment&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;I am your father.&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;when&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;2010-03-10 01:25:20&quot;</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br />
&nbsp; rating<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> stars<span style="color: #339933;">:</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">,</span> tagline<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;what a monster!&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; views<span style="color: #339933;">:</span> <span style="color: #CC0000;">1024</span><span style="color: #339933;">,</span><br />
&nbsp; trackbacks<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;url&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://some.blog/some/where&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;quote&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;the text for the link&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;url&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://some.other.blog/some/where/else&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;quote&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;the text they used to link here&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #009900;">&#93;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>So that might look like a more complex entity. It is, but you can search for values in sub-documents, you can filter results on existence of certain keys, and you can pull all this info one result. Your previous 7 tables and 8 joins, just became 1 collection and no joins. guess which is quicker?</p>
<p>Try to pull articles with a certain tag: &#8220;balls&#8221;? In SQL you&#8217;d be doing this:</p>
<div class="codecolorer-container sql mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="sql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">`article_id`</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">`tags_articles`</span> <span style="color: #ff0000;">`ta`</span> <span style="color: #993333; font-weight: bold;">JOIN</span> <span style="color: #ff0000;">`tags`</span> <span style="color: #ff0000;">`t`</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #ff0000;">`ta`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`tag_id`</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">`t`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`id`</span> <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #ff0000;">`t`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`name`</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'balls'</span></div></div>
<p>And that would just get you the list of Id&#8217;s and you&#8217;d still need to get the info for each article. In Mongo with the collection we described above, you&#8217;d do:</p>
<div class="codecolorer-container javascript mac-classic" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">db.<span style="color: #660066;">articles</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> tags<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;balls&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></div></div>
<p>How much easier is that, and we&#8217;ve now got all the info, not just the &#8220;id&#8221;s! I was just amazed at how easy that is!</p>
<p>Of course this simplicity comes with a price, you lose the relational elements making tight relationships harder to work with. Also you some ease in aggregating things like &#8220;tags&#8221;, but MapReduce support makes this very efficient anyway.</p>
<p>In my next blog I&#8217;ll talk about Lithium, Mongo and how fast you can build a full blown web app with these tools.</p>
]]></content:encoded>
			<wfw:commentRss>http://thechriswalker.net/2010-03/mongo-and-the-coolness-of-document-oriented-databases.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
