{"id":327,"date":"2015-10-20T07:57:34","date_gmt":"2015-10-20T07:57:34","guid":{"rendered":"http:\/\/vargas-solar.com\/cloud-data-management\/?p=327"},"modified":"2015-10-20T07:57:34","modified_gmt":"2015-10-20T07:57:34","slug":"couchdb-a-first-touch","status":"publish","type":"post","link":"http:\/\/vargas-solar.com\/cloud-data-management\/2015\/10\/20\/couchdb-a-first-touch\/","title":{"rendered":"CouchDB: A first touch"},"content":{"rendered":"<p>This practical exercise is intended to make you reason about the differences of principles between \u201cclassic\u201d RDBMS and NoSQL servers for building and managing data. DO NOT expect to acquire an extensive practice of the use of the DBMS used here. Rather expect to be able to:<\/p>\n<ul>\n<li>Point out some of their principles concerning: data model, design process, internal and external data management, architecture;<\/li>\n<li>Compare these principles with those of classic RDBMS.<\/li>\n<\/ul>\n<p>Therefore we propose an exercise organized into two parts where you are supposed to run some tests and answer control questions for making sure that you are achieving the expected objective of the exercise.<\/p>\n<h2>Requirements<\/h2>\n<ul>\n<li><a href=\"http:\/\/couchdb.apache.org\/\">CouchDB<\/a><\/li>\n<li><a href=\"http:\/\/curl.haxx.se\/download.html\">cURL<\/a>\u00a0(<a href=\"http:\/\/www.paehl.com\/open_source\/?download=curl_740_0.zip\">cURL 4 Windows<\/a>)<\/li>\n<\/ul>\n<h2>Building and Querying a NoSQL Oriented Database<\/h2>\n<p>In this exercise you will populate and query a NoSQL database using data coming from the\u00a0<a href=\"http:\/\/developers.deezer.com\/api\/\">Deezer RESTful service<\/a>. In particular, you will use data related with the rock band Muse. For instance, the following links give access to Muse\u2019s albums and information about similar artists (note that Muse has the ID 705 in Deezer):<\/p>\n<ul>\n<li><a href=\"http:\/\/api.deezer.com\/artist\/705\/albums\">http:\/\/api.deezer.com\/artist\/705\/albums<\/a><\/li>\n<li><a href=\"http:\/\/api.deezer.com\/artist\/705\/related\">http:\/\/api.deezer.com\/artist\/705\/related<\/a><\/li>\n<\/ul>\n<h2>TO DO<\/h2>\n<h3>Creating and populating a database<\/h3>\n<ul>\n<li>Using a terminal,\u00a0<strong>create\u00a0<\/strong>the\u00a0<strong>database\u00a0<\/strong>Deezer:<\/li>\n<\/ul>\n<pre>curl -X PUT <a href=\"http:\/\/localhost:5984\/deezer\"><em>http:\/\/localhost:5984\/deezer<\/em><\/a><\/pre>\n<ul>\n<li>Download (<em>and save into files<\/em>) the data about\u00a0<strong>Muse\u2019 album\u00a0<\/strong>and\u00a0<strong>similar artists<\/strong>:<\/li>\n<\/ul>\n<pre>curl -X GET <a href=\"http:\/\/api.deezer.com\/artist\/705\/albums\"><em>http:\/\/api.deezer.com\/artist\/705\/albums<\/em><\/a> &gt; MuseAlbums.json\r\ncurl -X GET <a href=\"http:\/\/api.deezer.com\/artist\/705\/related\"><em>http:\/\/api.deezer.com\/artist\/705\/related<\/em><\/a> &gt; MuseRelatedAlbums.json<\/pre>\n<ul>\n<li><strong>Populate<\/strong>\u00a0the Deezer\u00a0<strong>database\u00a0<\/strong>with the retrieved information by issuing the following commands:<\/li>\n<\/ul>\n<pre>curl -X PUT <a href=\"http:\/\/localhost:5984\/deezer\/muse_albums\"><em>http:\/\/localhost:5984\/deezer\/muse_albums<\/em><\/a> --upload-file \"MuseAlbums.json\"\r\ncurl -X PUT <a href=\"http:\/\/localhost:5984\/deezer\/muse_related_artists\"><em>http:\/\/localhost:5984\/deezer\/muse_related_artist<\/em><em>s<\/em><\/a> --upload-file \"MuseRelatedAlbums.json\"<\/pre>\n<ul>\n<li><strong>Verify<\/strong>\u00a0the content of the database:<\/li>\n<\/ul>\n<pre>curl -v <em><a href=\"http:\/\/localhost:5984\/deezer\/muse_albums\">http:\/\/localhost:5984\/deezer\/muse_albums\r\n<\/a><\/em>curl -v <em><a href=\"http:\/\/localhost:5984\/deezer\/muse_related_artists\">http:\/\/localhost:5984\/deezer\/muse_related_artists<\/a><\/em><\/pre>\n<p>Note that the output includes the HTTP request (<em>and reply<\/em>) headers sent to (<em>by<\/em>) CouchDB.<\/p>\n<ul>\n<li>Open\u00a0<strong>Fouton<\/strong>\u00a0(<em>CouchDB Web Interface<\/em>) on your browser:<\/li>\n<\/ul>\n<pre>http:\/\/127.0.0.1:5984\/_utils\/index.html<\/pre>\n<ul>\n<li>Access and observe the database\u00a0<strong>Deezer<\/strong>\u00a0on\u00a0<strong>Fouton<\/strong>.<\/li>\n<\/ul>\n<h3>Querying a database<\/h3>\n<p>Execute the following queries:<\/p>\n<ul>\n<li><strong>Query 1<\/strong>.\u00a0Retrieve the name and the web page of the groups that are similar to the rock band Muse.<\/li>\n<\/ul>\n<pre><strong>Map \r\n<\/strong>function(doc) {\r\n   \u2028var artists = doc.data;\u2028\r\n   if(doc._id == \"muse_related_artists\") {\r\n      for(var i in artists) \r\n         emit(artists[i].name, artists[i].link);\r\n   } \r\n}<\/pre>\n<ul>\n<li><strong>Query 2<\/strong>.\u00a0Compute the total number of the albums produced by the rock band Muse (requires to check the\u00a0<strong><em>reduce check button\u00a0<\/em><\/strong>in Fouton).<\/li>\n<\/ul>\n<pre><strong>Map \r\n<\/strong>function(doc) {\r\n   \u2028var artists = doc.data;\u2028\r\n   if(doc._id == \"muse_related_artists\") {\r\n      for(var i in artists) emit('muse_albums', 1);\r\n   }\r\n}<\/pre>\n<pre><strong>Reduce \r\n<\/strong>function(keys, values, rereduce) {\r\n   return sum(values);\r\n}<\/pre>\n<h3>Theoretic questions (TO ANSWER)<\/h3>\n<ul>\n<li>Is it possible to represent data under the classic relational model (see the 1 Normal Form)?<\/li>\n<li>Compare the notion of key in a relational schema with respect to the notion of key in key-value NoSQL approaches.<\/li>\n<li>Why is it necessary to define views for querying a database in CouchDB? Is this a way of integrating data? Justify.<\/li>\n<\/ul>\n<h2>REFERENCES<\/h2>\n<ul>\n<li>Book\u00a0<a href=\"http:\/\/guide.couchdb.org\/index.html\">CouchDB,\u00a0the definitive guide<\/a>.<\/li>\n<li><a href=\"http:\/\/en.wikipedia.org\/wiki\/NoSQL\">NoSQL<\/a>\u00a0definition.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This practical exercise is intended to make you reason about the differences of principles between &ldquo;classic&rdquo; RDBMS and NoSQL servers for building and managing data. DO NOT expect to acquire an extensive practice of the use of the DBMS used here. Rather expect to be able to: Point out some of their principles concerning: data [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-327","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/vargas-solar.com\/cloud-data-management\/wp-json\/wp\/v2\/posts\/327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/vargas-solar.com\/cloud-data-management\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/vargas-solar.com\/cloud-data-management\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/vargas-solar.com\/cloud-data-management\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"http:\/\/vargas-solar.com\/cloud-data-management\/wp-json\/wp\/v2\/comments?post=327"}],"version-history":[{"count":1,"href":"http:\/\/vargas-solar.com\/cloud-data-management\/wp-json\/wp\/v2\/posts\/327\/revisions"}],"predecessor-version":[{"id":328,"href":"http:\/\/vargas-solar.com\/cloud-data-management\/wp-json\/wp\/v2\/posts\/327\/revisions\/328"}],"wp:attachment":[{"href":"http:\/\/vargas-solar.com\/cloud-data-management\/wp-json\/wp\/v2\/media?parent=327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/vargas-solar.com\/cloud-data-management\/wp-json\/wp\/v2\/categories?post=327"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/vargas-solar.com\/cloud-data-management\/wp-json\/wp\/v2\/tags?post=327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}