<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Document-Oriented Persistence with CouchDB</title>
	<atom:link href="http://klena02.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://klena02.wordpress.com</link>
	<description>... a scalable, NoSql database</description>
	<lastBuildDate>Mon, 22 Nov 2010 08:28:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='klena02.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Document-Oriented Persistence with CouchDB</title>
		<link>http://klena02.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://klena02.wordpress.com/osd.xml" title="Document-Oriented Persistence with CouchDB" />
	<atom:link rel='hub' href='http://klena02.wordpress.com/?pushpress=hub'/>
		<item>
		<title>MSc Project Report: Document-Oriented Persistence with CouchDB</title>
		<link>http://klena02.wordpress.com/2010/09/22/document-oriented-persistence-with-couchdb/</link>
		<comments>http://klena02.wordpress.com/2010/09/22/document-oriented-persistence-with-couchdb/#comments</comments>
		<pubDate>Wed, 22 Sep 2010 13:47:37 +0000</pubDate>
		<dc:creator>klena02</dc:creator>
				<category><![CDATA[CouchDB]]></category>

		<guid isPermaLink="false">http://klena02.wordpress.com/?p=114</guid>
		<description><![CDATA[So here, finally, is my Project Report for my MSc Computer Science project at Birkbeck, University of London. I did the project on non-relational (so-called &#8216;NoSql&#8217;) databases, with a particular focus on CouchDB. The most interesting thing about CouchDB is that it combines, in the same product, a web server with a database. It can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=klena02.wordpress.com&amp;blog=11777260&amp;post=114&amp;subd=klena02&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So here, finally, is my <a href="http://klena02.files.wordpress.com/2010/09/documentorientedpersistencewithcouchdb-msc.pdf">Project Report for my MSc Computer Science project at Birkbeck, University of London</a>.</p>
<div id="attachment_127" class="wp-caption aligncenter" style="width: 248px"><a href="http://klena02.files.wordpress.com/2010/09/documentorientedpersistencewithcouchdb-msc.pdf"><img class="size-full wp-image-127" title="MSc Project Report: Document-Oriented Persistence with CouchDB" src="http://klena02.files.wordpress.com/2010/09/msc.png?w=238&#038;h=325" alt="MSc Project Report: Document-Oriented Persistence with CouchDB" width="238" height="325" /></a><p class="wp-caption-text">MSc Project Report: Document-Oriented Persistence with CouchDB</p></div>
<p>I did the project on non-relational (so-called &#8216;NoSql&#8217;) databases, with a particular focus on CouchDB. The most interesting thing about CouchDB is that it combines, in the same product, a web server with a database. It can store data as well as serve web pages. This enables it to do very interesting things such as the replication of data and code between servers, desktop PCs, and mobile devices.</p>
<p>Here&#8217;s a useful 2-minute video <a href="http://www.couchone.com/page/why-mobile">introduction to CouchDB</a>.</p>
<p>To understand CouchDB more deeply, <a href="http://guide.couchdb.org/">read the definitive guide</a>. That was my starting point for the project.</p>
<p><a href="http://www.couchone.com/"><img class="aligncenter" src="http://upload.wikimedia.org/wikipedia/commons/a/a5/Couchdb-logo.png" alt="CouchDB logo" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/klena02.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/klena02.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/klena02.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/klena02.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/klena02.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/klena02.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/klena02.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/klena02.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/klena02.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/klena02.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/klena02.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/klena02.wordpress.com/114/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/klena02.wordpress.com/114/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/klena02.wordpress.com/114/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=klena02.wordpress.com&amp;blog=11777260&amp;post=114&amp;subd=klena02&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://klena02.wordpress.com/2010/09/22/document-oriented-persistence-with-couchdb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/da6127616af6e004810c87a50da4f526?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">klena02</media:title>
		</media:content>

		<media:content url="http://klena02.files.wordpress.com/2010/09/msc.png" medium="image">
			<media:title type="html">MSc Project Report: Document-Oriented Persistence with CouchDB</media:title>
		</media:content>

		<media:content url="http://upload.wikimedia.org/wikipedia/commons/a/a5/Couchdb-logo.png" medium="image">
			<media:title type="html">CouchDB logo</media:title>
		</media:content>
	</item>
		<item>
		<title>Three Steps to CouchDB Heaven &#8230;</title>
		<link>http://klena02.wordpress.com/2010/08/16/three-steps-to-couchdb-heaven/</link>
		<comments>http://klena02.wordpress.com/2010/08/16/three-steps-to-couchdb-heaven/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 10:50:46 +0000</pubDate>
		<dc:creator>klena02</dc:creator>
				<category><![CDATA[CouchDB]]></category>

		<guid isPermaLink="false">http://klena02.wordpress.com/?p=80</guid>
		<description><![CDATA[&#8230; just follow and you will plain-lee see! Well, actually there are way more than three steps, but today, we&#8217;ll keep it to three, in honour of the King of Rock and Roll who died this day in 1977, aged 42. Step 1: Find some JSON documents in need of some CouchDB love So, let&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=klena02.wordpress.com&amp;blog=11777260&amp;post=80&amp;subd=klena02&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8230; just follow and you will plain-lee see!</p>
<p>Well, actually there are way more than three steps, but today, we&#8217;ll keep it to three, in honour of the <a href="http://en.wikipedia.org/wiki/Elvis_Presley">King of Rock and Roll</a> who died this day in 1977, aged 42.</p>
<p><strong>Step 1: Find some JSON documents in need of some CouchDB love</strong></p>
<p>So, let&#8217;s say you have some JSON documents, all in a folder, like this:</p>
<p><a href="http://klena02.files.wordpress.com/2010/08/folder.png"><img src="http://klena02.files.wordpress.com/2010/08/folder.png?w=300&#038;h=285" alt="JSON Documents in a Folder" title="Folder" width="300" height="285" class="aligncenter size-medium wp-image-81" /></a></p>
<p>The documents contain valid JSON. The best way to verify this is using <a href="http://www.jsonlint.com">http://www.jsonlint.com</a>:</p>
<p><a href="http://klena02.files.wordpress.com/2010/08/jsonlint.png"><img src="http://klena02.files.wordpress.com/2010/08/jsonlint.png?w=300&#038;h=210" alt="" title="JSONLint" width="300" height="210" class="aligncenter size-medium wp-image-86" /></a></p>
<p>So anyway, these documents aren&#8217;t happy. They have so much to offer to the world, yet here they are languishing on your hard disk.</p>
<p>Let&#8217;s cheer them up a little by putting them on the Couch.</p>
<p>Now, if you haven&#8217;t got your &#8220;CouchDB in the cloud&#8221; yet stop reading this and go to <a href="http://www.couch.io/get">http://www.couch.io/get</a> and get one. You can also get one from the similarly excellent <a href="http://cloudant.com">http://cloudant.com</a>.</p>
<p>One tip. When you create your cloud instance of CouchDB, be sure not to leave it in &#8220;admin party&#8221; mode. Secure it with a username and password instead.</p>
<p><strong>Step 2: PUT your documents on the Couch</strong></p>
<p>So, how do we get your love-sick documents off your disk and up and into the heavens?</p>
<p>Well, we know that we can speak with CouchDB at any time using HTTP. To use HTTP from the command line, we can use the curl command. If you are using windows, you can install curl for windows: <a href="http://curl.haxx.se/download.html">http://curl.haxx.se/download.html</a>.</p>
<p>I&#8217;m using <a href="http://www.ubuntu.com/">Ubuntu Linux</a> because it&#8217;s free and it&#8217;s awesome.</p>
<p>To create a database on your new cloud-based CouchDB, you need to do this from the command line or terminal window:<br />
<code><br />
curl -X PUT http://username:password@mick.couchone.com/universities<br />
</code></p>
<p>To put a single document on to the database, do this:<br />
<code><br />
curl -X PUT http://username:password@mick.couchone.com/universities/test -d @test.json<br />
</code></p>
<p>Note a couple of things: you need to replace username, password, mick, universities, test with whatever your own variables are.</p>
<p>Also, please note that I used PUT not POST. Why? Well, we use PUT when we already know the _id of the JSON document. If you want CouchDB to assign a system-generated _id to your document, that&#8217;s when you use POST instead. More details here: <a href="http://wiki.apache.org/couchdb/HTTP_Document_API#PUT">http://wiki.apache.org/couchdb/HTTP_Document_API#PUT</a>.</p>
<p>&#8230; all being well, the server replies as follows:<br />
<code><br />
{"ok":true,"id":"test","rev":"1-3b717529ff0f515c2c5d8aa52a2c03ab"}<br />
</code></p>
<p>&#8230; and we can go and look at our test document here:</p>
<p><a href="http://mick.couchone.com/universities/test">http://mick.couchone.com/universities/test</a></p>
<p>To upload an entire folder to the Couch, I had to learn some bash scripting (on windows the same would be achieved with a windows batch file script).<br />
<code><br />
#!/bin/bash<br />
FILES=./universities/*<br />
for filepath in $FILES<br />
do<br />
  # get the file name from the file path<br />
  jsonfilename=$(echo $filepath | sed -e 's/.\/universities\///g')<br />
  # remove the .json extension to get the docname<br />
  docname=$(echo $jsonfilename | sed -e 's/.json//g')<br />
  url="http://username:password@mick.couchone.com/universities/${docname}"<br />
  # put the document into CouchDB<br />
  echo curl -X PUT "$url" -d @"$filepath"<br />
  curl -X PUT "$url" -d @"$filepath"<br />
done<br />
</code></p>
<p><a href="http://www.cyberciti.biz/faq/bash-loop-over-file/">This page</a> helped me to write the bash script.</p>
<p>I saved this bash script into a file called <code>loop</code>. I then ran it by invoking <code>bash loop</code> from the terminal, and watched my documents fly off to heaven, where they live now for everyone to enjoy.</p>
<p><a href="http://mick.couchone.com/universities/_all_docs">http://mick.couchone.com/universities/_all_docs</a></p>
<p>You can see the individual documents like this:</p>
<p><a href="http://mick.couchone.com/universities/University%20of%20St%20Andrews">http://mick.couchone.com/universities/University%20of%20St%20Andrews</a></p>
<p>&#8230; put the output into <a href="http://jsonlint.com/">http://jsonlint.com/</a> so you can see the structure of the JSON document properly.</p>
<p><strong>Step 3: Put on a SHOW</strong></p>
<p><a href="http://klena02.wordpress.com/2010/08/10/couchdb-design-documents/">Last time</a> we looked at how design documents can hold HTML, and apply the HTML to any document we have.</p>
<p>Our example was this, pretty simple and lame.</p>
<p><a href="http://mick.couchone.com/universities/_design/default/_show/id/University%20of%20Aberdeen">http://mick.couchone.com/universities/_design/default/_show/id/University%20of%20Aberdeen</a></p>
<p>&#8230; but, since it&#8217;s all &#8220;just HTML&#8221;, you can do this as well, to use the latitude and longitude on a Google map. (I used the example map code from <a href="http://code.google.com/apis/maps/documentation/javascript/tutorial.html">http://code.google.com/apis/maps/documentation/javascript/tutorial.html</a>.)</p>
<p>So let&#8217;s change <code>_show/id</code> in the url to <code>_show/googlemap</code>, so that the output is produced by a different server-side javascript function.</p>
<p><a href="http://mick.couchone.com/universities/_design/default/_show/googlemap/University%20of%20Aberdeen">http://mick.couchone.com/universities/_design/default/_show/googlemap/University%20of%20Aberdeen</a></p>
<p>So, all I&#8217;ve done here is add a show to my design document. The name of the show is &#8220;googlemap&#8221;.</p>
<p><a href="http://mick.couchone.com/_utils/document.html?universities/_design/default">The design document is here</a>.</p>
<p>The design document also contains a view and a list, which enables us to link to all the individual google maps.</p>
<p><a href="http://mick.couchone.com/universities/_design/default/_list/defaultlist/defaultview">http://mick.couchone.com/universities/_design/default/_list/defaultlist/defaultview</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/klena02.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/klena02.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/klena02.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/klena02.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/klena02.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/klena02.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/klena02.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/klena02.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/klena02.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/klena02.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/klena02.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/klena02.wordpress.com/80/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/klena02.wordpress.com/80/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/klena02.wordpress.com/80/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=klena02.wordpress.com&amp;blog=11777260&amp;post=80&amp;subd=klena02&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://klena02.wordpress.com/2010/08/16/three-steps-to-couchdb-heaven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/da6127616af6e004810c87a50da4f526?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">klena02</media:title>
		</media:content>

		<media:content url="http://klena02.files.wordpress.com/2010/08/folder.png?w=300" medium="image">
			<media:title type="html">Folder</media:title>
		</media:content>

		<media:content url="http://klena02.files.wordpress.com/2010/08/jsonlint.png?w=300" medium="image">
			<media:title type="html">JSONLint</media:title>
		</media:content>
	</item>
		<item>
		<title>CouchDB Design Documents</title>
		<link>http://klena02.wordpress.com/2010/08/10/couchdb-design-documents/</link>
		<comments>http://klena02.wordpress.com/2010/08/10/couchdb-design-documents/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 21:51:12 +0000</pubDate>
		<dc:creator>klena02</dc:creator>
				<category><![CDATA[CouchDB]]></category>

		<guid isPermaLink="false">http://klena02.wordpress.com/?p=69</guid>
		<description><![CDATA[Hello folks, I&#8217;m back. Did you miss me? Oh how nice of you to say so. So when we last chatted I mentioned I was doing my Master&#8217;s project about CouchDB. To get started with CouchDB, go and get a CouchDB instance hosted by the wonderful people at couch.io: http://www.couch.io/get Today, I want to talk [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=klena02.wordpress.com&amp;blog=11777260&amp;post=69&amp;subd=klena02&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hello folks, I&#8217;m back. Did you miss me? Oh how nice of you to say so.</p>
<p>So when we last chatted I mentioned I was doing my Master&#8217;s project about CouchDB.</p>
<p>To get started with CouchDB, go and get a CouchDB instance hosted by the wonderful people at couch.io:<br />
<a href="http://www.couch.io/get">http://www.couch.io/get</a></p>
<p>Today, I want to talk a little about design documents in CouchDB.</p>
<p>Don&#8217;t be scared, stay with me and we&#8217;ll have a great time.</p>
<p>A design document in CouchDB is a document which stores application code.<br />
<a href="http://mick.couchone.com/universities/_design/default">http://mick.couchone.com/universities/_design/default</a></p>
<p>Let&#8217;s see if we can try to understand this design document, and what it is doing.</p>
<p>Look at this url &#8211; it&#8217;s a little bit crazy.<br />
<a href="http://mick.couchone.com/universities/_design/default/_show/id/Aberystwyth%20University">http://mick.couchone.com/universities/_design/default/_show/id/Aberystwyth%20University</a></p>
<p>So, what does this crazy url consist of?</p>
<p><a href="http://mick.couchone.com/universities">http://mick.couchone.com/universities</a> is a database.</p>
<p>To see it in &#8220;glorious technicolor&#8221;, you can use the built-in CouchDB utility, Futon: <a href="http://mick.couchone.com/_utils/database.html?universities">http://mick.couchone.com/_utils/database.html?universities</a></p>
<p>Are you more of a purist? Want to see all the documents in this database in no-frills json format?<br />
<a href="http://mick.couchone.com/universities/_all_docs">http://mick.couchone.com/universities/_all_docs</a><br />
Note that what you see here is a set of key-value pairs.</p>
<p>You put data in to CouchDB in the form of JSON documents.<br />
Internally, CouchDB stores the data in the form of indexed key-value pairs.</p>
<p>Anyway, sorry for that digression, let&#8217;s return to that crazy url.</p>
<p><a href="http://mick.couchone.com/universities">http://mick.couchone.com/universities</a> is our database.</p>
<p>CouchDB is a document-oriented database &#8211; it contains &#8211; yes, you guessed it &#8211; documents.</p>
<p>Most of the documents contain data, in our case data to do with universities, like this one.<br />
<a href="http://mick.couchone.com/universities/Aberystwyth%20University">http://mick.couchone.com/universities/Aberystwyth%20University</a></p>
<p><strong>One of the many amazing things about CouchDB is that documents can contain anything.</strong></p>
<p>So, as well as having documents that contain data, we can also &#8211; wait for it &#8211; have documents that contain code as well.</p>
<p>As we all know it&#8217;s a very very good idea to separate code from data.<br />
So, CouchDB likes us to put code in design documents.</p>
<p>The way I like to think about it is that a design document is like an application, using the data in the database.</p>
<p>Anyway, because I am very unimaginative I have called my application &#8220;default&#8221;.</p>
<p>So, to create my application, I create a design document, and give it an id according to CouchDB&#8217;s special naming convention.</p>
<p><a href="http://mick.couchone.com/universities/_design/default">http://mick.couchone.com/universities/_design/default</a></p>
<p>The database is &#8220;universities&#8221;, the name of the document is &#8220;_design/default&#8221; &#8211; it&#8217;s a little confusing to have a forward slash in the name of the document, but that&#8217;s the convention that CouchDB uses for design documents.</p>
<p>Within the design document, there is a section named &#8220;shows&#8221;. This gives us a way to show the data for a particular document.</p>
<p><code><br />
  "shows":{<br />
    "id":"function(doc,req){ return '&lt;h1&gt;' + doc._id + '&lt;/h1&gt;' }"<br />
  }<br />
</code></p>
<p>Here, I&#8217;ve defined one show, called &#8220;id&#8221;. It&#8217;s a function which accepts as parameters a document (doc) and a request object (req).</p>
<p>This is the url to access this show.<br />
<a>http://mick.couchone.com/universities/_design/default/_show/id/Aberystwyth%20University</a></p>
<p>This one is very simple. You can see how you could use this to build up a web page showing all the data relating to a particular university.</p>
<p>That&#8217;s what I intend to do next.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/klena02.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/klena02.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/klena02.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/klena02.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/klena02.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/klena02.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/klena02.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/klena02.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/klena02.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/klena02.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/klena02.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/klena02.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/klena02.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/klena02.wordpress.com/69/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=klena02.wordpress.com&amp;blog=11777260&amp;post=69&amp;subd=klena02&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://klena02.wordpress.com/2010/08/10/couchdb-design-documents/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/da6127616af6e004810c87a50da4f526?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">klena02</media:title>
		</media:content>
	</item>
		<item>
		<title>Project Proposal</title>
		<link>http://klena02.wordpress.com/2010/04/03/project-proposal-2/</link>
		<comments>http://klena02.wordpress.com/2010/04/03/project-proposal-2/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 19:40:49 +0000</pubDate>
		<dc:creator>klena02</dc:creator>
				<category><![CDATA[CouchDB]]></category>

		<guid isPermaLink="false">http://klena02.wordpress.com/?p=64</guid>
		<description><![CDATA[Here&#8217;s my project proposal.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=klena02.wordpress.com&amp;blog=11777260&amp;post=64&amp;subd=klena02&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://klena02.files.wordpress.com/2010/04/proposal.pdf">Here&#8217;s my project proposal</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/klena02.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/klena02.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/klena02.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/klena02.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/klena02.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/klena02.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/klena02.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/klena02.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/klena02.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/klena02.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/klena02.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/klena02.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/klena02.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/klena02.wordpress.com/64/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=klena02.wordpress.com&amp;blog=11777260&amp;post=64&amp;subd=klena02&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://klena02.wordpress.com/2010/04/03/project-proposal-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/da6127616af6e004810c87a50da4f526?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">klena02</media:title>
		</media:content>
	</item>
		<item>
		<title>CouchDB</title>
		<link>http://klena02.wordpress.com/2010/02/01/couchdb/</link>
		<comments>http://klena02.wordpress.com/2010/02/01/couchdb/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 09:59:54 +0000</pubDate>
		<dc:creator>klena02</dc:creator>
				<category><![CDATA[CouchDB]]></category>

		<guid isPermaLink="false">http://klena02.wordpress.com/?p=6</guid>
		<description><![CDATA[A database in CouchDB is simply a collection of documents. election-2005 is a database containing results from all UK constituencies for the 2005 election, taken from www.electoralcalculus.co.uk. &#160; Each document has a unique ID (in this case I&#8217;m using the constituency name), and a revision number (shown in green) which is used to provide concurrency [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=klena02.wordpress.com&amp;blog=11777260&amp;post=6&amp;subd=klena02&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A database in CouchDB is simply a collection of documents. election-2005 is a database containing results from all UK constituencies for the 2005 election, taken from <a href="http://www.electoralcalculus.co.uk/">www.electoralcalculus.co.uk</a>.</p>
<p><a href="http://klena02.files.wordpress.com/2010/02/010-futonoverview1.png"><img class="alignleft size-full wp-image-16" title="010-FutonOverview" src="http://klena02.files.wordpress.com/2010/02/010-futonoverview.png?w=700" alt="Futon Overview" width="700"></a></p>
<p>&nbsp;</p>
<p>Each document has a unique ID (in this case I&#8217;m using the constituency name), and a revision number (shown in green) which is used to provide concurrency control.</p>
<p><a href="http://klena02.files.wordpress.com/2010/02/020-election-2005.png"><img class="alignleft" title="Election Results" src="http://klena02.files.wordpress.com/2010/02/020-election-2005.png?w=700" alt="" width="700"></a></p>
<p>&nbsp;</p>
<p>A constituency record, showing total electorate plus votes for con, lab, lib, Plaid Cymru (pc), and others.</p>
<p><a href="http://klena02.files.wordpress.com/2010/02/030-aberavon.png"><img class="alignleft size-full wp-image-21" title="030-Aberavon" src="http://klena02.files.wordpress.com/2010/02/030-aberavon.png?w=700&#038;h=490" alt="" width="700" height="490"></a></p>
<p>&nbsp;</p>
<p>The same record in its native JSON format.</p>
<p><a href="http://klena02.files.wordpress.com/2010/02/031-aberavon-json.png"><img class="alignleft size-full wp-image-23" title="031-Aberavon-JSON" src="http://klena02.files.wordpress.com/2010/02/031-aberavon-json.png?w=700&#038;h=490" alt="" width="700" height="490"></a></p>
<p>&nbsp;</p>
<p>Here&#8217;s how to query the collection: in this case to get all constituencies, ordered by number of Conservative votes. CouchDB requires us to supply a Map function, which ranges of the document collection, and emits a set of key-value pairs. This creates an index on this value in the B+ tree.</p>
<p><a href="http://klena02.files.wordpress.com/2010/02/040-conservative-votes-asc.png"><img class="alignleft size-full wp-image-24" title="040-Conservative-Votes-ASC" src="http://klena02.files.wordpress.com/2010/02/040-conservative-votes-asc.png?w=700&#038;h=490" alt="" width="700" height="490"></a></p>
<p>&nbsp;</p>
<p>Just in case you&#8217;re interested, the constituency with the highest number of Conservative votes is the Isle of Wight.</p>
<p><a href="http://klena02.files.wordpress.com/2010/02/050-conservative-votes-desc.png"><img class="alignleft size-full wp-image-25" title="050-Conservative-Votes-DESC" src="http://klena02.files.wordpress.com/2010/02/050-conservative-votes-desc.png?w=700&#038;h=490" alt="" width="700" height="490"></a></p>
<p>&nbsp;</p>
<p>Now, let&#8217;s look at a where clause. Let&#8217;s say you want to get all constituencies where number of Conservative votes is between 1000 and 2000. What we want is to retrieve a sub-set from the index we created a minute ago. To do this, we append a query string on the end of the url: <strong>startkey=1000&amp;endkey=2000</strong>.</p>
<div style="width:700px;"><a href="http://klena02.files.wordpress.com/2010/02/051-conservative-votes-1000-2000.png"><img class="aligncenter size-full wp-image-26" title="051-Conservative-Votes-1000-2000" src="http://klena02.files.wordpress.com/2010/02/051-conservative-votes-1000-2000.png?w=672&#038;h=530" alt="" width="672" height="530"></a></div>
<p>&nbsp;</p>
<p>Finally, here is an aggregate of all Conservative votes (8,782,198). To do this, we use a Reduce function, which sums the values produced by the Map function.</p>
<p><a href="http://klena02.files.wordpress.com/2010/02/060-conservative-votes-total.png"><img class="alignleft size-full wp-image-27" title="060-Conservative-Votes-Total" src="http://klena02.files.wordpress.com/2010/02/060-conservative-votes-total.png?w=700&#038;h=490" alt="" width="700" height="490"></a></p>
<p><a href="http://klena02.files.wordpress.com/2010/02/070-conservative-votes-total.png"><img src="http://klena02.files.wordpress.com/2010/02/070-conservative-votes-total.png?w=700&#038;h=117" alt="" title="070-Conservative-Votes-Total" width="700" height="117" class="alignleft size-full wp-image-60" /></a></p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/klena02.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/klena02.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/klena02.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/klena02.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/klena02.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/klena02.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/klena02.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/klena02.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/klena02.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/klena02.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/klena02.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/klena02.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/klena02.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/klena02.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=klena02.wordpress.com&amp;blog=11777260&amp;post=6&amp;subd=klena02&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://klena02.wordpress.com/2010/02/01/couchdb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/da6127616af6e004810c87a50da4f526?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">klena02</media:title>
		</media:content>

		<media:content url="http://klena02.files.wordpress.com/2010/02/010-futonoverview.png" medium="image">
			<media:title type="html">010-FutonOverview</media:title>
		</media:content>

		<media:content url="http://klena02.files.wordpress.com/2010/02/020-election-2005.png" medium="image">
			<media:title type="html">Election Results</media:title>
		</media:content>

		<media:content url="http://klena02.files.wordpress.com/2010/02/030-aberavon.png" medium="image">
			<media:title type="html">030-Aberavon</media:title>
		</media:content>

		<media:content url="http://klena02.files.wordpress.com/2010/02/031-aberavon-json.png" medium="image">
			<media:title type="html">031-Aberavon-JSON</media:title>
		</media:content>

		<media:content url="http://klena02.files.wordpress.com/2010/02/040-conservative-votes-asc.png" medium="image">
			<media:title type="html">040-Conservative-Votes-ASC</media:title>
		</media:content>

		<media:content url="http://klena02.files.wordpress.com/2010/02/050-conservative-votes-desc.png" medium="image">
			<media:title type="html">050-Conservative-Votes-DESC</media:title>
		</media:content>

		<media:content url="http://klena02.files.wordpress.com/2010/02/051-conservative-votes-1000-2000.png" medium="image">
			<media:title type="html">051-Conservative-Votes-1000-2000</media:title>
		</media:content>

		<media:content url="http://klena02.files.wordpress.com/2010/02/060-conservative-votes-total.png" medium="image">
			<media:title type="html">060-Conservative-Votes-Total</media:title>
		</media:content>

		<media:content url="http://klena02.files.wordpress.com/2010/02/070-conservative-votes-total.png" medium="image">
			<media:title type="html">070-Conservative-Votes-Total</media:title>
		</media:content>
	</item>
	</channel>
</rss>
