Getting Started with NoSQL
Chapters
This course introduces you to NoSQL databases and touch on various subjects. We will use CouchDb to explain things that are common with many NoSQL databases.
This course is divided into 16 chapters
- Intro
- Prerequisites
- What is NoSQL
- What kinds of data stores are available.
- Learn CAP theorem
- When to use NoSQL databases.
- CouchDB
- Install CouchDB on Windows
- Install CouchDB on Linux.
- Storing data
- Retreive stored data
- Querying data, Creating customer views and using Map Reduce function
- A word on attachments, querying attachments and deplying a simple webpage application on CouchDB
- Securing CouchDB
- Partitioning
- Other NoSQL databases and A word on where to go from here.
We hope that you will enjoy this course. If you have any feedback please send it through.
Author: Subject Coach
Added on: 2nd Jan 2015
Please get in touch with your teacher or tutor in case you have a question related to this lesson
None just yet!
CouchDB allows use of binary data such as Images, You can upload files to your documents or server an application through CouchDB service.
Let's go back to our blog database and upload images to couple of our posts.
To upload an attachment, select the document, and then click on Upload attachment button. Browse the image file that you wish to upload.
Click on Upload button, Image will now be available as attachment. underscore attachments field keeps track of all the document attachments. Save your Document.
When you click on attachment itself you are able to see it. Or you can type in the path as, http://127.0.0.1:5984/blog/ ID of the document / image name.
You can delete this image by click on little cross icon.
Let's upload another image for our second post.
WHen you click on the Source tab, you will notice that underscore attachment object will have all the details for our uploaded image.
Let's now create a view that will return one attachment, for each document that has an attachment!. Goto views drop down and select temporary view from the list.
Copy code from query_attachment.txt under exercise folder and paste into the Map Function field.
Let me explain What this code is doing, its checking for all documents that have an attachment, and then! a complicated loop that is iterating over all attachments.
If! condition is making sure that key is not of type function, next line emits document name and key as value.
Loop is will halt after first iteration over attachments array.
Click Run button and you will see the result. We will save this Map function as a view, name it with underscore images. We will update this code a bit later in this chapter.
As I mentioned before, CouchDB allows us to run Javascript application, I have written a very basic web page.
You will find it under exercise files and test.html. Let's goto our blog database and then select All documents from the views drop down.
Goto underscore design / posts. You will see all the custom views we created earlier. Upload test.html to this design document.
After upload is finished click on test.html file link. You will see document title and attachment being displayed for all posts that has an attachment.
Let me now show you what code is behind test.html file.
First we including j query from Google CDN. We are then making use of our custom view called with underscore images.
Because the result will be in JSON format, thus we are using J query function called dollar dot get JSON. $.getJSON takes first argument as the URL end point and second as the call back function with parameter data.
We know that the returned data will be an object with property rows holding an object array.
We iterate over this data to create our view and appending created HTML tags to our container element with ID posts.
If I update my view and change emit function to return document content as key, saving the view, and go back to our test.html file, you will notice that our page data has been updated auto magically.
In next video we will look at how to secure our CouchDB installation.