Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
tsgolintはいかにしてtypescript-goの非公開APIを呼び出しているのか
syumai
7
2.3k
Jetpack XR SDKから紐解くAndroid XR開発と技術選定のヒント / about-androidxr-and-jetpack-xr-sdk
drumath2237
1
180
C-Shared Buildで突破するAI Agent バックテストの壁
po3rin
0
410
tparseでgo testの出力を見やすくする
utgwkk
2
260
チームをチームにするEM
hitode909
0
360
ELYZA_Findy AI Engineering Summit登壇資料_AIコーディング時代に「ちゃんと」やること_toB LLMプロダクト開発舞台裏_20251216
elyza
2
510
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
0
280
ゲームの物理 剛体編
fadis
0
370
これならできる!個人開発のすゝめ
tinykitten
PRO
0
120
Flutter On-device AI로 완성하는 오프라인 앱, 박제창 @DevFest INCHEON 2025
itsmedreamwalker
1
140
SwiftUIで本格音ゲー実装してみた
hypebeans
0
470
Context is King? 〜Verifiability時代とコンテキスト設計 / Beyond "Context is King"
rkaga
10
1.4k
Featured
See All Featured
KATA
mclloyd
PRO
33
15k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
78
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
320
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
400
Code Review Best Practice
trishagee
74
19k
We Have a Design System, Now What?
morganepeng
54
7.9k
The Limits of Empathy - UXLibs8
cassininazir
1
190
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.3k
The Pragmatic Product Professional
lauravandoore
37
7.1k
Typedesign – Prime Four
hannesfritz
42
2.9k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
180
エンジニアに許された特別な時間の終わり
watany
105
220k
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