<?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>source code bean &#187; NoSQL</title>
	<atom:link href="http://sourcecodebean.com/archives/category/nosql/feed" rel="self" type="application/rss+xml" />
	<link>http://sourcecodebean.com</link>
	<description>giving you tricks and tips of good coding</description>
	<lastBuildDate>Sun, 06 Jun 2010 16:40:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Trying out CouchDB for the first time</title>
		<link>http://sourcecodebean.com/archives/trying-out-couchdb-for-the-first-time/480</link>
		<comments>http://sourcecodebean.com/archives/trying-out-couchdb-for-the-first-time/480#comments</comments>
		<pubDate>Mon, 08 Mar 2010 06:05:59 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[NoSQL]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=480</guid>
		<description><![CDATA[There are several good libraries that will abstract accessing CouchDB. However, in order to understand what goes on in the libraries, I think it is important to first understand what is going on on a lower lever, so that is what I will show you. 
Step 1, install CouchDB. CouchDB for OSX can be downloaded [...]]]></description>
			<content:encoded><![CDATA[<p>There are several good libraries that will abstract accessing CouchDB. However, in order to understand what goes on in the libraries, I think it is important to first understand what is going on on a lower lever, so that is what I will show you. </p>
<p>Step 1, install CouchDB. CouchDB for OSX can be downloaded <a href="http://janl.github.com/couchdbx/">here</a>, the bundle contains bouth the Erlang runtime and CouchDB &#8211; no compiling or installing needed, just download the .dmg, mount it and run the application! If you are on Linux it is quite likely that CouchDB is in the repository of your distribution. In Ubuntu CouchDB is found in &#8220;Universe&#8221; and can easily be installed using apt. I haven&#8217;t tried CouchDB on Windows so I can&#8217;t give you any guidance here, if you try it out, please leave a comment. </p>
<p> Now when CouchDB is installed lets explore it using use one of my favorite tools, good old cURL. Port 5984 is the default port for CouchDB. </p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$ curl -X GET http:<span class="co1">//localhost:5984/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span><span class="st0">&quot;couchdb&quot;</span>:<span class="st0">&quot;Welcome&quot;</span>,<span class="st0">&quot;version&quot;</span>:<span class="st0">&quot;0.10.0&quot;</span><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>CouchDB is up running! Lets create a new database:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$ curl -X PUT http:<span class="co1">//localhost:5984/testdb</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span><span class="st0">&quot;ok&quot;</span>:<span class="kw2">true</span><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>CouchDB&#8217;s responses are also in JSON form. Lets inspect the database we just created:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$ curl -X GET http:<span class="co1">//localhost:5984/testdb</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;db_name&quot;</span>:<span class="st0">&quot;testdb&quot;</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="st0">&quot;doc_count&quot;</span>:<span class="nu0">0</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;doc_del_count&quot;</span>:<span class="nu0">0</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;update_seq&quot;</span>:<span class="nu0">0</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;purge_seq&quot;</span>:<span class="nu0">0</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;compact_running&quot;</span>:<span class="kw2">false</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="st0">&quot;disk_size&quot;</span>:<span class="nu0">79</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;instance_start_time&quot;</span>:<span class="st0">&quot;1266963717052501&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;disk_format_version&quot;</span>:<span class="nu0">4</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>CouchDB returns some statistics of the database, we can see that it contains 0 documents. Lets store an empty document in the database:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$ curl -X POST http:<span class="co1">//localhost:5984/testdb/ -H &quot;Content-Type: application/json&quot; -d {}</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;ok&quot;</span>:<span class="kw2">true</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="st0">&quot;id&quot;</span>:<span class="st0">&quot;ef40feff87010a6ef3a45a16df5af977&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;rev&quot;</span>:<span class="st0">&quot;1-967a00dff5e02add41819138abb3284d&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>CouchDB returns the unique id for the document and the version number (did i mention that all documents are version controlled?:)). Next step is to fetch all documents:</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">$ curl -X GET http:<span class="co1">//localhost:5984/testdb/_all_docs</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;total_rows&quot;</span>:<span class="nu0">1</span>,</div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="st0">&quot;offset&quot;</span>:<span class="nu0">0</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;rows&quot;</span>:<span class="br0">&#91;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="st0">&quot;id&quot;</span>:<span class="st0">&quot;ef40feff87010a6ef3a45a16df5af977&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="st0">&quot;key&quot;</span>:<span class="st0">&quot;ef40feff87010a6ef3a45a16df5af977&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="st0">&quot;value&quot;</span>:<span class="br0">&#123;</span><span class="st0">&quot;rev&quot;</span>:<span class="st0">&quot;1-967a00dff5e02add41819138abb3284d&quot;</span><span class="br0">&#125;</span></div>
</li>
<li class="li2">
<div class="de2">&nbsp; <span class="br0">&#125;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
</ol>
</div>
<p>Yes! it is there! Now you should also be able to see your database &#8220;testdb&#8221; and the document you created in the CouchDB GUI.</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/trying-out-couchdb-for-the-first-time/480/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CouchDB a NoSQL database</title>
		<link>http://sourcecodebean.com/archives/couchdb-a-nosql-database/460</link>
		<comments>http://sourcecodebean.com/archives/couchdb-a-nosql-database/460#comments</comments>
		<pubDate>Mon, 01 Mar 2010 20:44:29 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[NoSQL]]></category>

		<guid isPermaLink="false">http://sourcecodebean.com/?p=460</guid>
		<description><![CDATA[Traditionally relational databases has been the primary way of storing, sorting and searching data, and for most purposes they are very good at it. However, in the last few years &#8211; with the growth of cloud computing and sites such as Facebook pushing relational databases to its limits, people have started to look for other [...]]]></description>
			<content:encoded><![CDATA[<p>Traditionally relational databases has been the primary way of storing, sorting and searching data, and for most purposes they are very good at it. However, in the last few years &#8211; with the growth of cloud computing and sites such as Facebook pushing relational databases to its limits, people have started to look for other alternatives. The problems with relational databases is that it has been hard to scale them in a vertical way (scale them over several servers with linear, or close to linear, performance increase). A few databases in a cluster is no problem, but when it comes to several terabytes of data, which should be searched in real time, they are simply not enough. CouchDB and the other NoSQL databases aims to provide a truly horizontally scalable database.</p>
<p>NoSQL is a umbrella term for a wide variety of data stores, which all have in common that they do not store data in a relational way. Some examples of NoSQL databases are CouchDB, MongoDB, Amazon SimpleDB and Google BigTable. This is some of the properties they have in common:</p>
<p><strong>1. No schema</strong><br />
The data is stored in one big hashtable like data structure. No schema is needed. </p>
<p><strong>2. No more joins</strong><br />
Joins are slow in general, when they are spread out over several servers it gets even worse. In CouchDB there is no join, instead data should be duplicated. This might sound odd if you like me was taucht back in collage that normalization is of highest importance, and that you should really really avoid to duplicate data in your database. This is still true for most relational databases, but keep in mind that when relational databases was invented, disk space was expensive and normalization was a great way to save a few bytes. Storage is everything but expensive today, this is why NoSQL empathizes that data should instead be duplicated. </p>
<p><strong>3. Eventual consistency</strong><br />
When you update the database there is no longer a quarantine that all subsequent queries will get the updated value immediately, it might take some time depending on the system load. For some systems such as banking systems, this kind of behavior would be a big no no. But for most large web sites, this is no problem, the data is going to be cached in one way or another anyway. </p>
<p><br/></p>
<h2>CouchDB</h2>
<p>CouchDB is a document database, accessible via a RESTful JSON API. Everything stored in the database is a &#8220;document&#8221; and is stored in a flat address space.There are no schemas, the documents are stored and retrieved as JSON objects.</p>
<p>To address this problem of adding structure back to semi-structured data, CouchDB has something called &#8220;views&#8221;. A view is as close as we gets to a SQL query. The views are expressed in Javascript and consist of map and filter functions. They are built dynamically and will not affect the underlying data.</p>
<p>CouchDB is written in Erlang and runs on all systems that the Erlang runtime supports (Linux, Windows, OSX and other unix systems). I have tested CouchDB on Linux and OSX. This is a screenshot of the CouchDBX GUI running on OSX:<br />
<a href="http://sourcecodebean.com/wp-content/uploads/2010/02/couchdb.png"><img src="http://sourcecodebean.com/wp-content/uploads/2010/02/couchdb.png" alt="" title="couchdb" width="500" height="337" class="aligncenter size-full wp-image-469" /></a></p>
<p>The JSON representation of the same document:<br />
<a href="http://sourcecodebean.com/wp-content/uploads/2010/02/couchdb2.png"><img src="http://sourcecodebean.com/wp-content/uploads/2010/02/couchdb2.png" alt="" title="couchdb2" width="500" height="388" class="aligncenter size-full wp-image-474" /></a></p>
<p>In my next post I will show you some hands on action with CouchDB.</p>
]]></content:encoded>
			<wfw:commentRss>http://sourcecodebean.com/archives/couchdb-a-nosql-database/460/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
