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
230
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
兎に角、コードレビュー
mitohato14
0
120
Google I/O recap web編 大分Web祭り2025
kponda
0
2.9k
Gemini CLIの"強み"を知る! Gemini CLIとClaude Codeを比較してみた!
kotahisafuru
3
1.1k
Bedrock AgentCore ObservabilityによるAIエージェントの運用
licux
9
680
ゲームの物理
fadis
5
1.2k
エンジニアのための”最低限いい感じ”デザイン入門
shunshobon
0
110
CEDEC2025 長期運営ゲームをあと10年続けるための0から始める自動テスト ~4000項目を50%自動化し、月1→毎日実行にした3年間~
akatsukigames_tech
0
140
実践 Dev Containers × Claude Code
touyu
1
200
What's new in Adaptive Android development
fornewid
0
140
あのころの iPod を どうにか再生させたい
orumin
2
2.5k
Amazon Q CLI開発で学んだAIコーディングツールの使い方
licux
3
180
Langfuseと歩む生成AI活用推進
licux
3
230
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
351
21k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.6k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3k
Why You Should Never Use an ORM
jnunemaker
PRO
58
9.5k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3.1k
4 Signs Your Business is Dying
shpigford
184
22k
Practical Orchestrator
shlominoach
190
11k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Building an army of robots
kneath
306
45k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
30
9.6k
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