SlideShare uma empresa Scribd logo
1 de 21
Baixar para ler offline
Emily Stolfo
Ruby Engineer at 10gen
@EmStolfo
MongoDB and Rails fit
 together naturally
Ruby engineer on the drivers team




art historian



                consultant
                                                        adjunct faculty
                                                        at Columbia



                             web (Rails) developer
Learning Rails is unconventional

you have to be resourceful

  ○ example projects
  ○ online tutorials
  ○ community
Rails has conventions

DSL                  ActiveRecord
convention over      rvm
configuration        bundler
blackboxed           gems community
DRY                  MVC
All http stuff was   github
written already
ActiveRecord

● ActiveRecord bridges the gap between
  OOP and a relational database

● mongodb is OO natively

● Rails was built for a relational database
what is                    ?
MongoDB comes from the word ______.

It is a ______ database that is highly
______ and released under the ______
license, making it ______.

It stores data in ______ format and is
often favored for the ______ experience
because it is ______.
What is Ruby?
Ruby was created by ______.

Ruby is extremely ______ and ______ to
use.

It is known for seeing everything as an
______ and for the ______ experience.
What is a mongodb driver?
 1. connection pooling

 2. serialization/deserialization
     BSON<->hashes
 3. wire protocol
 4. classes for server stuff
    ex: abstracts RS, sharded cluster

  https://github.com/mongodb/mongo-ruby-driver/
@connection = MongoClient.new("localhost", 27017)
@data           = @connection.db("data")
@users          = @data.collection("users")
emily = {
            :name => "Emily",
            :age       => 28,
            :langs     => ["Ruby", "Python", "C++"],
            :favorites   => {
               :artists => ["George Bellows", "Rodin"],
               :color    => "Blue",
               :movies   => ["Old Boy", "Gladiator"]
               }
            }

@users.insert(emily)
@users.find({:name => "Emily"})   # name = "Emily"

@users.find({:age => {"$lt" => 30 } } )   # age < 30

@users.find({
   :age => {"$lt" => 30 },      # ... AND ...
   :langs => "Ruby",            # look in array
   "favorites.color" => "Blue", # reach into objects
    } )
emily = @users.find_one({:name => "Emily"})
emily.langs << "Lisp"
@users.save(emily) # too late?




@users.update(
   { :name => "Emily" },
   { :$push => { :langs => "Lisp" } }
   )
@sites.update(
   {:url => "http://www.nytimes.com"},
   { :$inc => { :visits => 1 } },
   :upsert => true )
Mongo::MongoReplicaSetClient.new(
   ['localhost:3000', 'localhost:3001', 'localhost:3002' ] )




Mongo::MongoShardedClient.new(
   ['localhost:3000', 'localhost:3001', 'localhost:3002' ]
)
ODM: Mongoid

   How do we get Ruby, Rails, and
    MongoDB to work together?

Object Document Mapper available
           as a gem

Used to be community ODM, with its
            own driver
User and Favorite
                                  model files

class User
   include Mongoid::Document
   field :name, type: String
   field :age, type: Integer
   field :langs, type: Array

      has_many :favorites
end
class Favorite
    include Mongoid::Document
    field :artists, type: Array
    field :color, type: String
    field :movies, type: Array

      belongs_to :user
end
Docs in MongoDB

# The parent user document
{
   "_id" : ObjectId("512e8fdab074c63e71dc6500"),
   "name" : "Emily",
   "age" : 28,
   "langs" : ["Ruby", "Python", "C++"],
}

# The child favorite document
{
   "_id" : ObjectId("512e8fdab074c63e71dc6501"),
   "artists" : ["George Bellows", "Rodin"],
   "color" : "Blue",
   "movies" : ["Old Boy", "Gladiator"],
   "user_id" : ObjectId("512e8fdab074c63e71dc6500")
}
User and Favorite
                                  model files

class User
   include Mongoid::Document
   field :name, type: String
   field :age, type: Integer
   field :langs, type: Array

      embeds_one :favorite
end
class Favorite
    include Mongoid::Document
    field :artists, type: Array
    field :color, type: String
    field :movies, type: Array

      embedded_in :user
end
Docs in MongoDB


# The user info and favorites in a single document
{
   "_id" : ObjectId("512e8fdab074c63e71dc6500"),
   "name" : "Emily",
   "age" : 28,
   "langs" : ["Ruby", "Python", "C++"],
   "favorite" : {
          "artists" : ["George Bellows", "Rodin"],
          "color" : "Blue",
          "movies" : ["Old Boy", "Gladiator"],
       }
}
Thanks!
     Keep using resources and the community

   Check out the ruby driver and submit a pull
                    request
          https://github.com/mongodb/mongo-ruby-driver/


               Try out mongoDB and Mongoid




Emily Stolfo
@EmStolfo

Mais conteúdo relacionado

Último

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Último (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

MongoDB, Ruby on Rails, and Mongoid

  • 1. Emily Stolfo Ruby Engineer at 10gen @EmStolfo
  • 2. MongoDB and Rails fit together naturally
  • 3. Ruby engineer on the drivers team art historian consultant adjunct faculty at Columbia web (Rails) developer
  • 4. Learning Rails is unconventional you have to be resourceful ○ example projects ○ online tutorials ○ community
  • 5. Rails has conventions DSL ActiveRecord convention over rvm configuration bundler blackboxed gems community DRY MVC All http stuff was github written already
  • 6. ActiveRecord ● ActiveRecord bridges the gap between OOP and a relational database ● mongodb is OO natively ● Rails was built for a relational database
  • 7. what is ? MongoDB comes from the word ______. It is a ______ database that is highly ______ and released under the ______ license, making it ______. It stores data in ______ format and is often favored for the ______ experience because it is ______.
  • 8. What is Ruby? Ruby was created by ______. Ruby is extremely ______ and ______ to use. It is known for seeing everything as an ______ and for the ______ experience.
  • 9. What is a mongodb driver? 1. connection pooling 2. serialization/deserialization BSON<->hashes 3. wire protocol 4. classes for server stuff ex: abstracts RS, sharded cluster https://github.com/mongodb/mongo-ruby-driver/
  • 10. @connection = MongoClient.new("localhost", 27017) @data = @connection.db("data") @users = @data.collection("users")
  • 11. emily = { :name => "Emily", :age => 28, :langs => ["Ruby", "Python", "C++"], :favorites => { :artists => ["George Bellows", "Rodin"], :color => "Blue", :movies => ["Old Boy", "Gladiator"] } } @users.insert(emily)
  • 12. @users.find({:name => "Emily"}) # name = "Emily" @users.find({:age => {"$lt" => 30 } } ) # age < 30 @users.find({ :age => {"$lt" => 30 }, # ... AND ... :langs => "Ruby", # look in array "favorites.color" => "Blue", # reach into objects } )
  • 13. emily = @users.find_one({:name => "Emily"}) emily.langs << "Lisp" @users.save(emily) # too late? @users.update( { :name => "Emily" }, { :$push => { :langs => "Lisp" } } )
  • 14. @sites.update( {:url => "http://www.nytimes.com"}, { :$inc => { :visits => 1 } }, :upsert => true )
  • 15. Mongo::MongoReplicaSetClient.new( ['localhost:3000', 'localhost:3001', 'localhost:3002' ] ) Mongo::MongoShardedClient.new( ['localhost:3000', 'localhost:3001', 'localhost:3002' ] )
  • 16. ODM: Mongoid How do we get Ruby, Rails, and MongoDB to work together? Object Document Mapper available as a gem Used to be community ODM, with its own driver
  • 17. User and Favorite model files class User include Mongoid::Document field :name, type: String field :age, type: Integer field :langs, type: Array has_many :favorites end class Favorite include Mongoid::Document field :artists, type: Array field :color, type: String field :movies, type: Array belongs_to :user end
  • 18. Docs in MongoDB # The parent user document { "_id" : ObjectId("512e8fdab074c63e71dc6500"), "name" : "Emily", "age" : 28, "langs" : ["Ruby", "Python", "C++"], } # The child favorite document { "_id" : ObjectId("512e8fdab074c63e71dc6501"), "artists" : ["George Bellows", "Rodin"], "color" : "Blue", "movies" : ["Old Boy", "Gladiator"], "user_id" : ObjectId("512e8fdab074c63e71dc6500") }
  • 19. User and Favorite model files class User include Mongoid::Document field :name, type: String field :age, type: Integer field :langs, type: Array embeds_one :favorite end class Favorite include Mongoid::Document field :artists, type: Array field :color, type: String field :movies, type: Array embedded_in :user end
  • 20. Docs in MongoDB # The user info and favorites in a single document { "_id" : ObjectId("512e8fdab074c63e71dc6500"), "name" : "Emily", "age" : 28, "langs" : ["Ruby", "Python", "C++"], "favorite" : { "artists" : ["George Bellows", "Rodin"], "color" : "Blue", "movies" : ["Old Boy", "Gladiator"], } }
  • 21. Thanks! Keep using resources and the community Check out the ruby driver and submit a pull request https://github.com/mongodb/mongo-ruby-driver/ Try out mongoDB and Mongoid Emily Stolfo @EmStolfo