24
Rails with MongoDB Eugene Park [email protected] 1

Rails with MongoDB

Embed Size (px)

Citation preview

Page 1: Rails with MongoDB

Rails with MongoDB

Eugene [email protected]

1

Page 2: Rails with MongoDB

More data usually beats better algorithms. 

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

by Anand Rajaraman

Page 3: Rails with MongoDB

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.

Page 4: Rails with MongoDB

3 Vs of Big Data

TDWI Research 2011 Big Data Analytic Report

Page 5: Rails with MongoDB

Decide.com

Page 6: Rails with MongoDB

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

Page 7: Rails with MongoDB

Big data landspace

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

Page 8: Rails with MongoDB

What is MongoDB

8

Page 9: Rails with MongoDB

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

Page 10: Rails with MongoDB

DB‐Engines ranking

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

Page 11: Rails with MongoDB

Use cases and production deployments

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

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

Page 12: Rails with MongoDB

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

Page 13: Rails with MongoDB

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

Page 14: Rails with MongoDB

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

Page 15: Rails with MongoDB

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

Page 16: Rails with MongoDB

Terminology

Page 17: Rails with MongoDB

Query

Page 18: Rails with MongoDB

Data modification

Page 19: Rails with MongoDB

Aggregation

Page 20: Rails with MongoDB

Map reduce

Page 21: Rails with MongoDB

MongoDB drivers

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

Page 22: Rails with MongoDB

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

Page 23: Rails with MongoDB

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• …

Page 24: Rails with MongoDB

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