Rails with MongoDB

Preview:

Citation preview

Rails with MongoDB

Eugene Parkstarville@me.com

1

More data usually beats better algorithms. 

2http://anand.typepad.com/datawocky/2008/03/more‐data‐usual.html

by Anand Rajaraman

Big Data

http://en.wikipedia.org/wiki/Big_data

• Big Data is the term for a collection of data sets so large and complex that it becomes difficult to process using on-hand database management tools or traditional data processing applications.

• Popularization of big data - SNS, Smart phone, Sensor, Open data.

• Hardware - reduce costs, increase efficiencies, Software Evolution.

• Cloud computing.

3 Vs of Big Data

TDWI Research 2011 Big Data Analytic Report

Decide.com

Big Data technology• Big Data technology stacks allow to effectively

capture, store, select and process data of big volume, variety and velocity. These technologies were invented by internet giants such as Yahoo, Google and Facebook because they first dealt with unstructured data on a large scale. Several key terms and principals are the backbones of the Big Data technologies

• NoSQL Systems• Key-Value Storages (including in-memory caches)• Map Reduce• Horizontal Scaling

http://www.dataart.com/software‐outsourcing/big‐data

Big data landspace

7http://mattturck.com/2012/10/15/a‐chart‐of‐the‐big‐data‐ecosystem‐take‐2/

What is MongoDB

8

Definition & history• MongoDB (from "humongous") is an open source document-oriented

database system developed and supported by 10gen. It is part of the NoSQL family of database systems. Instead of storing data in tables as is done in a "classical" relational database, MongoDB stores structured data as JSON-like documents with dynamic schemas (MongoDB calls the format BSON), making the integration of data in certain types of applications easier and faster.

• 10gen began development of MongoDB in October 2007. The database is used by eBay, MetLife, Telefónica, Foursquare, MTV Networks and the UK Government. MongoDB is the most popular NoSQL database management system.

• Binaries are available for Windows, Linux, OS X, and Solaris.• Development of MongoDB began at 10gen in 2007, when the company

was building a platform as a service similar to Windows Azure or Google App Engine. In 2009, MongoDB was open sourced as a stand-alone product with an AGPL license.

• In March 2010, from version 1.4, MongoDB has been considered production ready.

• The latest stable version, 2.4.6, was released in August 20 2013.

http://en.wikipedia.org/wiki/MongoDB

DB‐Engines ranking

http://db‐engines.com/en/ranking/

Use cases and production deployments

http://www.mongodb.org/about/production‐deployments/

• WEB APPLICATIONS• AGILE DEVELOPMENT• ANALYTICS AND LOGGING• CACHING• VARIABLE SCHEMAS

Concepts and philosophy• Scale-Out• NoSQL-Not only SQL • Document-oriented, JSON• BSON• Embedding, referencing

Document database• Not for .PDF & .DOC files• A document is essentially an associative array• Document == JSON OBJECT• Document == PHP Array• Document == Python Dictionary• Document == Ruby Hash• etc

Open source• MongoDB is an open source project• On GitHub• Licensed under the AGPL• Started & sponsored by 10gen• Commercial licenses available• Contributions welcome

Tips & limitations• 64-bit system will be necessary• Run on a dedicated server• Run with replication

Terminology

Query

Data modification

Aggregation

Map reduce

MongoDB drivers

http://docs.mongodb.org/ecosystem/drivers/

Installationsudo apt‐key adv ‐‐keyserver keyserver.ubuntu.com ‐‐recv 7F0CEB10

echo ʹdeb http://downloads‐distro.mongodb.org/repo/ubuntu‐upstart dist 10genʹ | sudo tee /etc/apt/sources.list.d/10gen.list

sudo apt‐get update

sudo apt‐get install mongodb‐10gen

Practice : Creating a blog in 15 minutes

• $ rails new blog ‐‐skip‐active‐record• $ cd blog• $ vi Gemfile

o gem ‘mongoid’, github: ʹmongoid/mongoidʹ o gem ʹbson_extʹ, ʹ~> 1.8.6‘o gem ʹexecjsʹo gem ʹtherubyracer‘

• $ bundle update• $ rails g mongoid:config• $ rails generate scaffold Post title:string content:text• $ rails s• …

Reference & useful sites• MongoDB in Action, Kyle Banker, MANNING• 빅데이터의충격, 시로타마코토, 한빛미디어• http://docs.mongodb.org/manual• http://www.10gen.com/presentations/webinar-building-your-

first-app• http://docs.mongodb.org/ecosystem/tools/• http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Ma

pping+Chart• http://education.mongodb.com• http://stackoverflow.com• http://Github.com• http://Wikipedia.org• Http://mongoid.org• http://rubyonrails.org