<?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>ijonas.com &#187; database</title>
	<atom:link href="http://ijonas.com/tag/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://ijonas.com</link>
	<description>Habitual Ramblings of an Indiginous Ijonous</description>
	<lastBuildDate>Mon, 02 Jan 2012 15:12:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Installing MongoDB 1.8.1 on Ubuntu 10.10 &amp; 11.04 and running with an &#8216;init&#8217; script.</title>
		<link>http://ijonas.com/software-development/nosql/398/</link>
		<comments>http://ijonas.com/software-development/nosql/398/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 11:37:17 +0000</pubDate>
		<dc:creator>ijonas</dc:creator>
				<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[1.8]]></category>
		<category><![CDATA[10Gen]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[init script]]></category>
		<category><![CDATA[init.d]]></category>
		<category><![CDATA[journal]]></category>
		<category><![CDATA[journaling]]></category>
		<category><![CDATA[maverick meerkat]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[ubuntu 10.10]]></category>
		<category><![CDATA[ubuntu 11.04]]></category>

		<guid isPermaLink="false">http://www.denofubiquity.com/?p=398</guid>
		<description><![CDATA[Installing MongoDB 1.8.1, in my case as a developer database, is easy. This blog post just itemises all the steps so that you can pretty blindly follow allong. I'll probably use these steps myself as I seem to be doing this regurlarly ;-)
 <a href="http://ijonas.com/software-development/nosql/398/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Installing MongoDB 1.8.1, in my case as a developer database, is easy. This blog post just itemises all the steps so that you can pretty much blindly follow along. I&#8217;ll probably use these steps myself as I seem to be doing this regurlarly <img src='http://ijonas.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Download the 64bit Linux binaries from <a title="MongoDB binaries download page" href="http://www.mongodb.org/downloads">here</a> and unzip the contents to /usr/local.</p>
<pre language="bash">cd /tmp
wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-1.8.1.tgz
sudo tar -zxf /tmp/mongodb-linux-x86_64-1.8.1.tgz -C /usr/local</pre>
<p>Setup some symbolic links.</p>
<pre language="bash">sudo ln -s /usr/local/mongodb-linux-x86_64-1.8.1 /usr/local/mongodb
sudo ln -s /usr/local/mongodb/bin/bsondump /usr/local/bin/bsondump
sudo ln -s /usr/local/mongodb/bin/mongo /usr/local/bin/mongo
sudo ln -s /usr/local/mongodb/bin/mongod /usr/local/bin/mongod
sudo ln -s /usr/local/mongodb/bin/mongodump /usr/local/bin/mongodump
sudo ln -s /usr/local/mongodb/bin/mongoexport /usr/local/bin/mongoexport
sudo ln -s /usr/local/mongodb/bin/mongofiles /usr/local/bin/mongofiles
sudo ln -s /usr/local/mongodb/bin/mongoimport /usr/local/bin/mongoimport
sudo ln -s /usr/local/mongodb/bin/mongorestore /usr/local/bin/mongorestore
sudo ln -s /usr/local/mongodb/bin/mongos /usr/local/bin/mongos
sudo ln -s /usr/local/mongodb/bin/mongosniff /usr/local/bin/mongosniff
sudo ln -s /usr/local/mongodb/bin/mongostat /usr/local/bin/mongostat</pre>
<p>The first &#8220;ln -s&#8221; above sets up a handy symbolic link between the versioned mongodb folder and its unversioned counterpart. When 10Gen release updates, say version 1.8.2, all you need to do is download, unzip, and link the &#8217;1.8.2 mongodb folder&#8217; to the unversioned folder and &#8216;hey presto&#8217; everything should just work.</p>
<p>To get an init script working cleanly with this setup, download mine from <a title="Ijonas' dotfiles repo" href="https://github.com/ijonas/dotfiles">my Github &#8216;dotfiles&#8217; repo</a>. Please note &#8211; my init script enables journaling and the REST interface (on line 51).</p>
<pre language="bash">wget https://github.com/ijonas/dotfiles/raw/master/etc/init.d/mongod
sudo mv mongod /etc/init.d/mongod
sudo chmod +x /etc/init.d/mongod
</pre>
<p>You&#8217;ll need to add a mongodb user and prep some folders</p>
<pre language="bash">sudo useradd mongodb
sudo mkdir -p /var/lib/mongodb
sudo mkdir -p /var/log/mongodb
sudo chown mongodb.mongodb /var/lib/mongodb
sudo chown mongodb.mongodb /var/log/mongodb</pre>
<p>Also, you need to activate your MongoDB service&#8217;s init script by adding it to your system&#8217;s run-level configuration. That way the service will startup during the boot sequence and stop nicely during the OS&#8217; shutdown procedure.</p>
<pre>
sudo update-rc.d mongod defaults
</pre>
<p>Lastly to launch MongoDB</p>
<pre language="bash">/etc/init.d/mongod start</pre>
<p>Good luck!</p>
<p><strong>UPDATE:</strong> Since April 6 Ubuntu now has prefabbed packages containing MongoDB 1.8.1, maintained by 10Gen. See the instruction below.</p>
<div style="padding-top:5px;padding-right:0px;padding-bottom:5px;padding-left:0px;;">
											<iframe
												style="height:25px !important; border:0px solid gray !important; overflow:hidden !important; width:460px !important;" frameborder="0" scrolling="no" allowTransparency="true"
												src="http://www.linksalpha.com/social?blog=ijonas.com&link=http%3A%2F%2Fijonas.com%2Fsoftware-development%2Fnosql%2F398%2F&title=Installing+MongoDB+1.8.1+on+Ubuntu+10.10+%26+11.04+and+running+with+an+%27init%27+script.&desc=Installing+MongoDB+1.8.1%2C+in+my+case+as+a+developer+database%2C+is+easy.+This+blog+post+just+itemises+all+the+steps+so+that+you+can+pretty+much+blindly+follow+along.+I%27ll+probably+use+these+steps+myself&fc=333333&fs=arial&fblname=like&fblref=facebook&fbllang=en_US&fblshow=1&fbsbutton=0&fbsctr=1&fbslang=en&fbsendbutton=0&twbutton=1&twlang=en&twmention=ijonas&twrelated1=&twrelated2=&twctr=1&lnkdshow=noshow&lnkdctr=1&buzzbutton=0&buzzlang=en&buzzctr=1&diggbutton=1&diggctr=1&stblbutton=1&stblctr=1&g1button=1&g1ctr=1&g1lang=en-US">
											</iframe>
										</div>]]></content:encoded>
			<wfw:commentRss>http://ijonas.com/software-development/nosql/398/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>CouchDB Presentation at Railscamp UK</title>
		<link>http://ijonas.com/software-development/108/</link>
		<comments>http://ijonas.com/software-development/108/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 21:29:27 +0000</pubDate>
		<dc:creator>ijonas</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[addressability]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[documents]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[horizontal scaling]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[metadata]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://ijonas.wordpress.com/?p=108</guid>
		<description><![CDATA[I&#8217;ve been playing around with and kicking the tyres of CouchDB for a couple of weeks and I&#8217;m truly excited about the project. If I was to use tags to describe CouchDB I&#8217;d use the following: apache, opensource, documents, metadata, &#8230; <a href="http://ijonas.com/software-development/108/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing around with and kicking the tyres of CouchDB for a couple of weeks and I&#8217;m truly excited about the project. If I was to use tags to describe CouchDB I&#8217;d use the following:</p>
<p><code>apache, opensource, documents, metadata, database, json, javascript, REST, addressability, horizontal scaling, erlang.</code></p>
<p>So I found myself at Railscamp UK on the weekend without a ruby+rails topic to really talk about during the presentations part of the camp. I&#8217;m still a noob wrt. Rails, you see. Realising that CouchDB is relevant to most web developers because most developers deal with document-based content at some point and that Ruby, Rails, and Erlang are kindda like the current bratpack (<a href="http://en.wikipedia.org/wiki/John_Hughes_(film_director)">in a John Hughes-sense</a>) of computer languages, I thought it would be a great little topic for a 15-minute presentation.</p>
<p>So I thought I share the slides and some of the code I hacked up on the weekend. First of all the slides&#8230;</p>
<p style="text-align:center;"><a href="http://www.scribd.com/doc/4916889/CouchDB-Railscamp-UK"><img class="aligncenter size-medium wp-image-113" src="http://ijonas.files.wordpress.com/2008/08/couchdb_slides.png?w=300" alt="" width="300" height="225" /></a></p>
<p style="text-align:center;"><a href="http://www.scribd.com/doc/4916889/CouchDB-Railscamp-UK" target="_blank">(click me)</a></p>
<p>You can play about with some sample code that was expanded upon after the presentation. Here&#8217;s a little helper class to interface into CouchDB using JSON and HTTP:</p>
<pre lang="ruby">require 'rubygems'
require 'httparty'
require 'json/pure'
require 'find'

class CouchHack
  include HTTParty
  base_uri 'http://127.0.0.1:5984'
  format :json

  def update( path, document )
    options = { :body => JSON.generate(document) }
    puts self.class.put(path, options )
  end

  def get(path)
    self.class.get(path)
  end

  def create(db_path, document )
    options = { :body => JSON.generate(document) }
    self.class.post(db_path, options )
  end

  def define_view(db_path, design_doc_name, views )
    document = { "views" => views }
    options = { :body => JSON.generate(document) }
    self.class.put("#{db_path}/_design/#{design_doc_name}", options)
  end
end</pre>
<p>Once that&#8217;s in place you can use the CouchHack class by defining a view like so:</p>
<pre lang="ruby">ch = CouchHack.new
gem_views = {
  "small_gems" =>
    {
      "map" => "function(doc) { if (doc.length < 3000) emit(doc.path, doc) }",
    },
  "large_gems" =>
    {
      "map" => "function(doc) { if (doc.length > 3000) emit(doc.path, doc) }",
    }
}
ch.define_view("/railscamp", "gems", gem_views)</pre>
<p>This design document, as is its known in CouchDB parleance, defines two views (think &#8216;baked queries&#8217;), to return a list of small gems &#8211; those less than 3000 bytes &#8211; and a list of large gems &#8211; those larger than 3000 bytes.</p>
<p>So where do these gems come from and how do they end up in CouchDB ? That&#8217;s what the next and last little fragment of Ruby code does.</p>
<pre lang="ruby">Find.find('/Library/Ruby/Gems/1.8/gems/' ) do |f|
  if File.file?(f) and f.ends_with?('.rb' )
    begin
      gem_contents = IO.read(f)
      gem_document = { "path" => f, "length" => gem_contents.length, "content" => gem_contents }
      ch.create( "/railscamp", gem_document )
    rescue Exception => bang
      puts "Skipping #{f}"
    end
  end
end</pre>
<p>So what happens is that the last little fragment traverses the filesystem starting at /Library/Ruby/Gems/1.8/gems/ and looks for *.rb files. When it finds one it POSTs that whole document including the file length to CouchDB, where it becomes part of the resultset of one of the pre-defined views. These views can be accessed through the following two URLs (assuming the &#8216;railscamp&#8217; DB was used).</p>
<ul>
<li><a href="http://localhost:5984/railscamp/_view/gems/large_gems">http://localhost:5984/railscamp/_view/gems/large_gems</a></li>
<li><a href="http://localhost:5984/railscamp/_view/gems/small_gems">http://localhost:5984/railscamp/_view/gems/small_gems</a></li>
</ul>
<p>Feel free to post comments and ask questions.</p>
<p>Enjoy.</p>
<p>P.S. and if you get a chance to go to a *camp conference, GO! They&#8217;re an amazing format and you&#8217;ll learn soooo much!.</p>
<div style="padding-top:5px;padding-right:0px;padding-bottom:5px;padding-left:0px;;">
											<iframe
												style="height:25px !important; border:0px solid gray !important; overflow:hidden !important; width:460px !important;" frameborder="0" scrolling="no" allowTransparency="true"
												src="http://www.linksalpha.com/social?blog=ijonas.com&link=http%3A%2F%2Fijonas.com%2Fsoftware-development%2F108%2F&title=CouchDB+Presentation+at+Railscamp+UK&desc=I%27ve+been+playing+around+with+and+kicking+the+tyres+of+CouchDB+for+a+couple+of+weeks+and+I%27m+truly+excited+about+the+project.+If+I+was+to+use+tags+to+describe+CouchDB+I%27d+use+the+following%3A%0A%0Aapache%2C+o&fc=333333&fs=arial&fblname=like&fblref=facebook&fbllang=en_US&fblshow=1&fbsbutton=0&fbsctr=1&fbslang=en&fbsendbutton=0&twbutton=1&twlang=en&twmention=ijonas&twrelated1=&twrelated2=&twctr=1&lnkdshow=noshow&lnkdctr=1&buzzbutton=0&buzzlang=en&buzzctr=1&diggbutton=1&diggctr=1&stblbutton=1&stblctr=1&g1button=1&g1ctr=1&g1lang=en-US">
											</iframe>
										</div>]]></content:encoded>
			<wfw:commentRss>http://ijonas.com/software-development/108/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

