SlideShare a Scribd company logo
Rails with MongoDB-2
Eugene Park
starville@me.com
Setup Ruby On Rails
on Ubuntu 13.04
• Installing Ruby with rvm
• Installing Rails
$ sudo apt-get update
$ Sudo apt-get install curl
$ curl -L https://get.rvm.io | bash -s stable
$ source ~/.rvm/scripts/rvm
$ rvm requriements
$ Sudo apt-get ...
$ rvm install 2.0.0
$ rvm use 2.0.0 --default
$ ruby -v
$ gem install rails
Installing MongoDB
on Ubuntu 13.04
• Configure Package Management System (APT)
• Install Packages
• configration
$ sudo apt-key adv --keyserver
hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
$ echo 'deb http://downloads-
distro.mongodb.org/repo/ubuntu-upstart dist
10gen' | sudo tee
/etc/apt/sources.list.d/mongodb.list
$ sudo apt-get update
$ sudo apt-get install mongodb-10gen
$ whereis mongodb.conf
Installing mongoid
• installing Mongoid is with bundler
• Configuration
$ vi Gemfile
gem 'mongoid', github: 'mongoid/mongoid‘
gem 'bson', github: 'mongodb/bson-ruby'
gem 'execjs‘
gem 'therubyracer‘
$ bundle update
$ Rails g mongoid:config
$ vi myapp/config/mongoid.yml
MongoDB SQL
Create Insert (Save) Insert
Read Find Select
Update Update (Upsert) Update
Delete Remove Delete
CRUD & the Mongoshell
book = {
_id : 10203040,
title : “Rails wth MongoDB Guide”,
auther : “Eugene Park”,
available : 987,
checkout : [ {by : “Eugene”, date : ISOdate(“2013-10-01”)}]
}
db.books.findAndModify({
query: {
_id : 10203040,
available: { $gt: 0 }
},
update: {
$inc : { available : -1},
$push : { checkout : { by: “Crayon”, data: new Date()}}
}
})
Atomic operations
Schema Design
• The data your application needs.
• How your application will read the data.
• How your application will write the data.
Traditional MongoDB
Your application doesn’t matter.
Only about the data.
Only relevant during design.
It’s always about your application.
Not only about the data, but also
how it’s used.
Relevant during the lifetime of your
application.
Blog data model
posts
id
author
title
Body
comments
id
post_id
tag_id
author
body
posts_tags
id
post_id
tag_id
tags
id
text
posts
id
title
body
tags[]
comment[
{author: …,body: …},
{…}
]
RDBMS MongoDB
Create blog apps
$ rails new blog –-skip-active-record
$ cd blog
$ vi Gemfile
#add and save
gem 'mongoid', github: 'mongoid/mongoid‘
gem 'bson', github: 'mongodb/bson-ruby'
gem 'execjs‘
gem 'therubyracer‘
$ bundle
$ rake g mongoid:config
$ rails g scaffold post title:string body:text tags:array
... ① string to array
$ Rails g model comment author:string body:text
... ② def relationship, routes
$ rails g controller comments
... ③ def create
... ④ create list, form for comment

More Related Content

PDF
iOS VoIP待ち受けの仕組み
KEY
Mysqlnd uh
PDF
Server-Side JavaScript Developement - Node.JS Quick Tour
PPTX
What is AWS S3?
PDF
Create a RESTful API with NodeJS, Express and MongoDB
PPTX
Jk rubyslava 25
PDF
Philipp Krenn "Elasticsearch (R)Evolution — You Know, for Search…"
PDF
Hujs 总结
iOS VoIP待ち受けの仕組み
Mysqlnd uh
Server-Side JavaScript Developement - Node.JS Quick Tour
What is AWS S3?
Create a RESTful API with NodeJS, Express and MongoDB
Jk rubyslava 25
Philipp Krenn "Elasticsearch (R)Evolution — You Know, for Search…"
Hujs 总结

What's hot (17)

PPTX
Event-driven IO server-side JavaScript environment based on V8 Engine
PPTX
Rubyslava + PyVo #48
PDF
Standardized API Development using Node.js
PDF
Mongo db in 3 minutes BoilerMake
PPT
Introducing to node.js
PDF
Node js quick tour v2
PPTX
Database Schema as Code
PDF
高性能かつスケールアウト可能なHPCクラウド AIST Super Green Cloud
PPTX
MongoDB's New Aggregation framework
PDF
2 docker engine_hands_on
 
PDF
Making web stack tasty using Cloudformation
PDF
Scrapy talk at DataPhilly
PDF
Jan Čurn: Meteor: the full-stack JavaScript framework
PPTX
Create Rest API in Nodejs
PPTX
Beyond Golden Containers: Complementing Docker with Puppet
PDF
PDF
Etcd terraform by Alex Somesan
Event-driven IO server-side JavaScript environment based on V8 Engine
Rubyslava + PyVo #48
Standardized API Development using Node.js
Mongo db in 3 minutes BoilerMake
Introducing to node.js
Node js quick tour v2
Database Schema as Code
高性能かつスケールアウト可能なHPCクラウド AIST Super Green Cloud
MongoDB's New Aggregation framework
2 docker engine_hands_on
 
Making web stack tasty using Cloudformation
Scrapy talk at DataPhilly
Jan Čurn: Meteor: the full-stack JavaScript framework
Create Rest API in Nodejs
Beyond Golden Containers: Complementing Docker with Puppet
Etcd terraform by Alex Somesan
Ad

Viewers also liked (6)

PDF
Rails with MongoDB
PDF
Km Overview
PPT
Ikt For Laerere
ODP
Poe presentation
PPT
Infoavond
PPTX
Zoekstrategieën
Rails with MongoDB
Km Overview
Ikt For Laerere
Poe presentation
Infoavond
Zoekstrategieën
Ad

Similar to Rails with MongoDB - RORLab 47th (20)

PDF
MongoDB and Ruby on Rails
PDF
Rails Loves MongoDB
PDF
Build your first MongoDB App in Ruby @ StrangeLoop 2013
PPTX
Rails + mongo db
KEY
MongoDB at RubyEnRails 2009
PDF
MongoDB.pdf
PDF
MongoDB at FrozenRails
PPTX
Simple MongoDB design for Rails apps
PDF
Mongodb
PPT
9. Document Oriented Databases
PDF
Using MongoDB and a Relational Database at MongoDB Day
PDF
Building your first app with MongoDB
PDF
Using Mongoid with Ruby on Rails
PDF
Mongodb By Vipin
KEY
MongoDB Strange Loop 2009
PPTX
Dev Jumpstart: Building Your First App
PDF
Introduction to MongoDB
PPT
Meetup#1: 10 reasons to fall in love with MongoDB
PDF
Webinar: Getting Started with Ruby and MongoDB
PDF
MongoDB
MongoDB and Ruby on Rails
Rails Loves MongoDB
Build your first MongoDB App in Ruby @ StrangeLoop 2013
Rails + mongo db
MongoDB at RubyEnRails 2009
MongoDB.pdf
MongoDB at FrozenRails
Simple MongoDB design for Rails apps
Mongodb
9. Document Oriented Databases
Using MongoDB and a Relational Database at MongoDB Day
Building your first app with MongoDB
Using Mongoid with Ruby on Rails
Mongodb By Vipin
MongoDB Strange Loop 2009
Dev Jumpstart: Building Your First App
Introduction to MongoDB
Meetup#1: 10 reasons to fall in love with MongoDB
Webinar: Getting Started with Ruby and MongoDB
MongoDB

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
cuic standard and advanced reporting.pdf
PPTX
Cloud computing and distributed systems.
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Encapsulation theory and applications.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Approach and Philosophy of On baking technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Review of recent advances in non-invasive hemoglobin estimation
sap open course for s4hana steps from ECC to s4
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Dropbox Q2 2025 Financial Results & Investor Presentation
NewMind AI Weekly Chronicles - August'25-Week II
cuic standard and advanced reporting.pdf
Cloud computing and distributed systems.
Spectral efficient network and resource selection model in 5G networks
MYSQL Presentation for SQL database connectivity
Assigned Numbers - 2025 - Bluetooth® Document
Network Security Unit 5.pdf for BCA BBA.
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Encapsulation theory and applications.pdf
Empathic Computing: Creating Shared Understanding
Unlocking AI with Model Context Protocol (MCP)
Approach and Philosophy of On baking technology
Machine learning based COVID-19 study performance prediction
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Digital-Transformation-Roadmap-for-Companies.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Review of recent advances in non-invasive hemoglobin estimation

Rails with MongoDB - RORLab 47th

  • 1. Rails with MongoDB-2 Eugene Park starville@me.com
  • 2. Setup Ruby On Rails on Ubuntu 13.04 • Installing Ruby with rvm • Installing Rails $ sudo apt-get update $ Sudo apt-get install curl $ curl -L https://get.rvm.io | bash -s stable $ source ~/.rvm/scripts/rvm $ rvm requriements $ Sudo apt-get ... $ rvm install 2.0.0 $ rvm use 2.0.0 --default $ ruby -v $ gem install rails
  • 3. Installing MongoDB on Ubuntu 13.04 • Configure Package Management System (APT) • Install Packages • configration $ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 $ echo 'deb http://downloads- distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list $ sudo apt-get update $ sudo apt-get install mongodb-10gen $ whereis mongodb.conf
  • 4. Installing mongoid • installing Mongoid is with bundler • Configuration $ vi Gemfile gem 'mongoid', github: 'mongoid/mongoid‘ gem 'bson', github: 'mongodb/bson-ruby' gem 'execjs‘ gem 'therubyracer‘ $ bundle update $ Rails g mongoid:config $ vi myapp/config/mongoid.yml
  • 5. MongoDB SQL Create Insert (Save) Insert Read Find Select Update Update (Upsert) Update Delete Remove Delete CRUD & the Mongoshell
  • 6. book = { _id : 10203040, title : “Rails wth MongoDB Guide”, auther : “Eugene Park”, available : 987, checkout : [ {by : “Eugene”, date : ISOdate(“2013-10-01”)}] } db.books.findAndModify({ query: { _id : 10203040, available: { $gt: 0 } }, update: { $inc : { available : -1}, $push : { checkout : { by: “Crayon”, data: new Date()}} } }) Atomic operations
  • 7. Schema Design • The data your application needs. • How your application will read the data. • How your application will write the data. Traditional MongoDB Your application doesn’t matter. Only about the data. Only relevant during design. It’s always about your application. Not only about the data, but also how it’s used. Relevant during the lifetime of your application.
  • 9. Create blog apps $ rails new blog –-skip-active-record $ cd blog $ vi Gemfile #add and save gem 'mongoid', github: 'mongoid/mongoid‘ gem 'bson', github: 'mongodb/bson-ruby' gem 'execjs‘ gem 'therubyracer‘ $ bundle $ rake g mongoid:config $ rails g scaffold post title:string body:text tags:array ... ① string to array $ Rails g model comment author:string body:text ... ② def relationship, routes $ rails g controller comments ... ③ def create ... ④ create list, form for comment