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
250
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
MongoDB & Rails
Intro to using MongoDB with Rails. Presented at Madrid-rb
Amaia Castro
February 28, 2013
Other Decks in Programming
See All in Programming
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
340
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
260
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
160
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
410
「人を評価する AI」の設計と実装
ryoyanara
0
180
源内ハンズオン概要編
hideg
0
150
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
180
Foundation Models frameworkで画像分析
ryodeveloper
1
600
仕様駆動開発の消費期限
watany
19
7.7k
PHP初心者セッション2026 〜生成AIでは見えない裏側を知る:今だからLAMPを通して仕組みを学ぶ〜
kashioka
0
880
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
490
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
370
Featured
See All Featured
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
BBQ
matthewcrist
89
10k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
WCS-LA-2024
lcolladotor
0
790
Believing is Seeing
oripsolob
1
180
How to make the Groovebox
asonas
2
2.3k
Building AI with AI
inesmontani
PRO
1
1.1k
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
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