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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
140
dchart: charts from deck markup
ajstarks
3
990
AtCoder Conference 2025
shindannin
0
1.1k
ノイジーネイバー問題を解決する 公平なキューイング
occhi
0
100
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
CSC307 Lecture 09
javiergs
PRO
1
840
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
700
CSC307 Lecture 03
javiergs
PRO
1
490
Apache Iceberg V3 and migration to V3
tomtanaka
0
160
それ、本当に安全? ファイルアップロードで見落としがちなセキュリティリスクと対策
penpeen
7
3.9k
CSC307 Lecture 02
javiergs
PRO
1
780
Featured
See All Featured
Making Projects Easy
brettharned
120
6.6k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
770
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
55
Agile that works and the tools we love
rasmusluckow
331
21k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.6k
How to Talk to Developers About Accessibility
jct
2
130
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
78
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
940
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
300
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
3.9k
Skip the Path - Find Your Career Trail
mkilby
0
56
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