Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
MongoDB & Rails
Search
Amaia Castro
February 28, 2013
Programming
4
240
MongoDB & Rails
Intro to using MongoDB with Rails. Presented at Madrid-rb
Amaia Castro
February 28, 2013
Tweet
Share
Other Decks in Programming
See All in Programming
余白を設計しフロントエンド開発を 加速させる
tsukuha
7
2.1k
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
140
Basic Architectures
denyspoltorak
0
670
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
130
OSSとなったswift-buildで Xcodeのビルドを差し替えられるため 自分でXcodeを直せる時代になっている ダイアモンド問題編
yimajo
3
620
FOSDEM 2026: STUNMESH-go: Building P2P WireGuard Mesh Without Self-Hosted Infrastructure
tjjh89017
0
170
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
380
izumin5210のプロポーザルのネタ探し #tskaigi_msup
izumin5210
1
130
[KNOTS 2026登壇資料]AIで拡張‧交差する プロダクト開発のプロセス および携わるメンバーの役割
hisatake
0
280
AIエージェント、”どう作るか”で差は出るか? / AI Agents: Does the "How" Make a Difference?
rkaga
4
2k
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
230
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
6.1k
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
The agentic SEO stack - context over prompts
schlessera
0
640
Into the Great Unknown - MozCon
thekraken
40
2.3k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
The Limits of Empathy - UXLibs8
cassininazir
1
210
Ruling the World: When Life Gets Gamed
codingconduct
0
140
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
180
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
340
The Spectacular Lies of Maps
axbom
PRO
1
520
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
78
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
0
140
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
200
Transcript
MongoDB & Rails madrid-rb
Amaia Castro Freelance Ruby on Rails developer amaiacastro.com github.com/amaia @amaiac
None
RDBMS Memcached MongoDB NoSQL SQL features scale & speed
MongoDB Dynamic queries Secondary indexes Joins Transactions Referential integrity
Document
"JSON" { name: "mongo", type: "DB" }
Collections of documents
MongoDB + Rails = Mongoid (Object-Document-Mapper) Queries Validations Callbacks Associations
Tags posts tags SQL MongoDB posts_tags ------------ post_id tag_id {
title: "MongoDB", tags: [ "mongodb", "madrid-rb", "ruby" ] } posts class Post include Mongoid:: Document field :title field :tags, type: Array end
Invoice invoice invoice_line ------------ invoice_id SQL MongoDB { invoice_number: "01",
invoice_lines: [ {...}, {...} ] }
class Invoice include Mongoid::Document field :number, type: String embeds_many :invoice_lines
end class InvoiceLine include Mongoid::Document field :description, type: String field :price, type: BigDecimal embedded_in :invoice end
Users & Groups users groups SQL MongoDB groups_users ------------ user_id
group_id { _id: "abc123", username: "amaia", groups: [ "654dbd", ... ] } { _id: "654dbd", name: "madrid- rb", users: [ "abc123", ... ] } users groups
Real Life Example
ActiveRecord + Mongoid config ├── database.yml └── mongoid.yml tip: activate
safe_mode in mongoid.yml
class PersonalProfile include Mongoid::Document field :user_id, :type => Integer field
:name, :type => String field :interests, :type => Array field :skills, :type => Array def user User.find_by_id(self.user_id) end end class User < ActiveRecord::Base def personal_profile PersonalProfile.where(user_id: self.id).first end end
• No joins or transactions at DB level • Model
your data as independent documents • Avoid referenced associations in Mongoid • Mix and match SQL and NoSQL when needed Summary
Thank you