Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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 ins...
Installing MongoDB
on Ubuntu 13.04
• Configure Package Management System (APT)
• Install Packages
• configration
$ sudo ap...
Installing mongoid
• installing Mongoid is with bundler
• Configuration
$ vi Gemfile
gem 'mongoid', github: 'mongoid/mongo...
MongoDB SQL
Create Insert (Save) Insert
Read Find Select
Update Update (Upsert) Update
Delete Remove Delete
CRUD & the Mon...
book = {
_id : 10203040,
title : “Rails wth MongoDB Guide”,
auther : “Eugene Park”,
available : 987,
checkout : [ {by : “E...
Schema Design
• The data your application needs.
• How your application will read the data.
• How your application will wr...
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
tex...
Create blog apps
$ rails new blog –-skip-active-record
$ cd blog
$ vi Gemfile
#add and save
gem 'mongoid', github: 'mongoi...
Upcoming SlideShare
Loading in …5
×

Rails with MongoDB - RORLab 47th

1,366 views

Published on

Rails with MongoDB - RORLab 47th
Oct 8, 2013

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Rails with MongoDB - RORLab 47th

  1. 1. Rails with MongoDB-2 Eugene Park starville@me.com
  2. 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. 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. 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. 5. MongoDB SQL Create Insert (Save) Insert Read Find Select Update Update (Upsert) Update Delete Remove Delete CRUD & the Mongoshell
  6. 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. 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.
  8. 8. 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
  9. 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

×