Watching:  

Getting Started with NoSQL


Author: Subject Coach
Added on: 2nd Jan 2015

 
Please note: You need to login to view this resource

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

  1. Intro
  2. Prerequisites 
  3. What is NoSQL
  4. What kinds of data stores are available.
  5. Learn CAP theorem
  6. When to use NoSQL databases.
  7. CouchDB
  8. Install CouchDB on Windows
  9. Install CouchDB on Linux.
  10. Storing data
  11. Retreive stored data
  12. Querying data, Creating customer views and using Map Reduce function
  13. A word on attachments, querying attachments and deplying a simple webpage application on CouchDB
  14. Securing CouchDB
  15. Partitioning
  16. 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 querying through JavaScript. This is very unlike!SQL.
I've added one more post to our blog database, so that I can show you how to use search criteria.
You can get the JSON data for this post from post_2.txt file under exercise folder.
Let me quickly show you our posts, by opening them in new tabs.
Our second post has similar post fields as our first post without a couple of fields.

Let's now create a custom search filter or view, by clicking on the View drop down, then selecting temporary view from the options.
On this page you will see two sections, one to be used for Map and another will be used to reduce our result set.

In Map function documents in the collection that match the query condition get returned. In reduce phase, function collects and condenses the aggregated data.

Let's check out what Map phase does for us.

If Map function field is empty? then copy paste javascript function from map.js file available in exercise folder.
Click Run button, You will see all the documents available in our database here, with keys labelled as null. You can choose how many documents to show by clicking on "Rows per page" drop down and
selecting the number.

The emit() function always takes two arguments: the first is key, and the second is value.
emit() function can also be called multiple times in the map function to create multiple entries in the view results from a single document, but we just concentrate on simplicity for the time being.

let's change emit function to display name value as key. When you hit Run button! key updates itself from null to doc dot name value.

You can also add a filter condition, such as, return all documents where value of name field is "post".

When you click run button, only documents with name post, will show up.

You can save this filter as a view. Start with assigning name "posts" to design document.
A design document can be used in building an application and group views under a single roof.
We will name this view as "all"!
You will notice that under Views drop down we now have our view entry. You can get a JSON output by removing underscore utills/database dot html, question mark from the URL

Let's create another view. Go back to View drop down and select Temporary View.

update the condition to filter by author name. When you click run button, posts written by author will show up. Let's save this view as by underscore jas underscore chahal.

Now we have 2 custom views.

Let's now use Reduce function to check how many posts we've got in our database.
Copy and paste Reduce function from reduce.txt into the Reduce function field. reduce function takes 3 arguments. key, values and rereduce. We are return values count from this function. When you return more than one value, the reduce function is called recursively, in this scenario, rereduce is set to true.

Reduce function is called only once for each key. There are 2 entries for posts and one entry for options.
This is important because the reduce function is going to be called once for posts, even though we've got two entries and once for options.

Once done, click On Run button, you may have to refresh your page. You will notice a Reduce check box, Which you should tick, magic happens just then. Reduce function is

applied to the mapped data.

Let's update our filter to only show count for posts. Click Run button and you will see results for key posts.

Save this view as total underscore posts under design document posts.

You are now able to switch between different filters we've created.

As usual, You can get a JSON output by removing underscore utills/database dot html, question mark.

In next video we will see how you can manage attachments for our posts.