SlideShare ist ein Scribd-Unternehmen logo
1 von 34
MONGODB AND RUBY
Persisting dynamic data with MongoMapper
MONGODB

• humongous                        • auto-sharding

• Speed!!!                         • replication   and fail-over

• document-oriented      storage   • GridFS
 (BSON)
                                   • MapReduce
• dynamic    queries
                                   • Schemaless
• fast, in-place   updates
USE IT FOR..

• (most) Websites

• Caching

• Scalabilty
SKIP IT FOR..

• Transactions

• Lots   of joins

• Fixed   datasets (science,...)
START USING IT
• MongoDB   in google: www.mongodb.org - Quickstart

 • make   a directory

 • download   mongodb

 • unpack
START USING IT
START USING IT
QUERYING

> db.fosdem.save({talk: "MongoDB", presenter: "Bernard"})
> db.fosdem.find()
{
  "_id" : ObjectId("4b681a1ecf1bcfea49f4b2ae"),
  "talk" : "MongoDB",
  "presenter" : "Bernard"
}
MORE QUERYING

> db.fosdem.find({presenter: "Bernard")
{
  "_id" : ObjectId("4b681a1ecf1bcfea49f4b2ae"),
  "talk" : "MongoDB",
  "presenter" : "Bernard"
}
MORE QUERYING
gem install mongo_mapper
  gem install mongo_ext
require 'mongo_mapper'
MongoMapper.database = ‘fosdem’
class Presenter
  include MongoMapper::Document
end
class Presenter
  include MongoMapper::Document

 key :name, String
 key :confirmed, Boolean
 key :keywords, Array
 key :presentation, Presentation
end
presenter = Presenter.new({
  :name => “Bernard”,
  :confirmed => true,
  :keywords => [“Openminds”, “geek”]
})
presenter.save
presenter.destroy
ACTIVERECORD, ANYONE?
MONGOMAPPER HAS


• validates_*

• before_save   / after_update / ...

• has_many   / belongs_to

• timestamps!
CUSTOM DATATYPES
class Keywords                                        class Presenter
   def initialize(array)                                include MongoMapper::Document
      @words = array                                    key :keywords, Keywords
   end                                                end

  def to_a
    @words
  end

  class << self
     def to_mongo(value)
        value.is_a?(Keyword) ? keyword.to_a : value
     end

    def from_mongo(value)
      value ? self.new(value) : nil
    end
  end
end
EMBEDDED DOCUMENT


include MongoMapper::EmbeddedDocument
DYNAMIC?
INHERITANCE

class Page                 class BlogPost < Page
  key :permalink, String     key :content, String
  key :title, String         has_many :comments
end                        end

                           class Redirect < Page
                             key :destination, String
                           end
MODULAR
module Authentication
 def self.included(base)
   base.key :password, String
   base.key :salt, String
   base.key :login, String
 end
end

class Person
  include MongoMapper::Document
  include Authentication
end
MULTISITE WEBSHOP
    EXAMPLE
   per instance data gathering
ORDERS AS A DOCUMENT
class Order
   include MongoMapper::Document
   key :order_id, String

  class << self
     def for_site(site)
        klass = Class.new(self)
        klass.order_fields = site.order_fields
        Object.const_set("OrderForSite#{site.id}", klass)
        klass
     end

    def order_fields=(fields)
      fields.each do |field|
         key field, String
      end
    end
  end
end
ORDERS: MONGOMAPPER


    class Order
      include MongoMapper::Document
      key :order_id, String
ORDER: CLASS FOR A SPECIFIC
           SITE

     def for_site(site)
      klass = Class.new(self)
      klass.order_fields = site.order_fields
      Object.const_set("OrderForSite#{site.id}", klass)
      klass
     end
DYNAMIC DOCUMENT
    BUILDING

 def order_fields=(fields)
  fields.each do |field|
    key field, String
  end
 end
PER USER
class Order
   include MongoMapper::Document
   key :order_id, String

  class << self
     def for_site(site)
        klass = Class.new(self)
        klass.order_fields = site.order_fields
        Object.const_set("OrderForSite#{site.id}", klass)
        klass
     end

    def order_fields=(fields)
      fields.each do |field|
         key field, String
      end
    end
  end
end
SITE


• Can   be a Mongo-document

• Can   be an ActiveRecord object

• Can   be a (Rails 3) ActiveModel object (REST?)

• Has   to “respond_to? :id” and “respond_to? :order_fields”
TRY IT OUT


current_site.order_fields
#=> [“field1”, “field2”]
@order = Order.for_site(current_site).new
#=> #<OrderForSite2172858380 field1: nil, field2: nil,
order_id: nil>
Q&A
1
                                                               2
                                                               3
                                                               4
                                                               5
                                                               6
                                                               7
• Bernard   Grymonpon




                                                               8
                                                               9
                                                               10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
• Openminds    BVBA

• Hosting   & Rails-shop                 ribbit




• @wonko_be     - @openminds_be


                                  Top sites deserve
                                  maximum uptime

                                  openminds.be
                                  tailored hosting solutions

Weitere ähnliche Inhalte

Was ist angesagt?

MongoDB at ZPUGDC
MongoDB at ZPUGDCMongoDB at ZPUGDC
MongoDB at ZPUGDCMike Dirolf
 
Introduction to couch_db
Introduction to couch_dbIntroduction to couch_db
Introduction to couch_dbRomain Testard
 
MongoDB and Ecommerce : A perfect combination
MongoDB and Ecommerce : A perfect combinationMongoDB and Ecommerce : A perfect combination
MongoDB and Ecommerce : A perfect combinationSteven Francia
 
Product catalog using MongoDB
Product catalog using MongoDBProduct catalog using MongoDB
Product catalog using MongoDBVishwas Bhagath
 
Mongo NYC PHP Development
Mongo NYC PHP Development Mongo NYC PHP Development
Mongo NYC PHP Development Fitz Agard
 
Xml dom & sax by bhavsingh maloth
Xml dom & sax by bhavsingh malothXml dom & sax by bhavsingh maloth
Xml dom & sax by bhavsingh malothBhavsingh Maloth
 

Was ist angesagt? (8)

MongoDB at ZPUGDC
MongoDB at ZPUGDCMongoDB at ZPUGDC
MongoDB at ZPUGDC
 
Introduction to couch_db
Introduction to couch_dbIntroduction to couch_db
Introduction to couch_db
 
MongoDB and Ecommerce : A perfect combination
MongoDB and Ecommerce : A perfect combinationMongoDB and Ecommerce : A perfect combination
MongoDB and Ecommerce : A perfect combination
 
Product catalog using MongoDB
Product catalog using MongoDBProduct catalog using MongoDB
Product catalog using MongoDB
 
Mongo NYC PHP Development
Mongo NYC PHP Development Mongo NYC PHP Development
Mongo NYC PHP Development
 
Unit 3 (it workshop).pptx
Unit 3 (it workshop).pptxUnit 3 (it workshop).pptx
Unit 3 (it workshop).pptx
 
KeyValue Stores
KeyValue StoresKeyValue Stores
KeyValue Stores
 
Xml dom & sax by bhavsingh maloth
Xml dom & sax by bhavsingh malothXml dom & sax by bhavsingh maloth
Xml dom & sax by bhavsingh maloth
 

Andere mochten auch

Lee-Anne - Indiv Researc
Lee-Anne - Indiv ResearcLee-Anne - Indiv Researc
Lee-Anne - Indiv ResearcLee-Anne P
 
Mashing it Up in the Classroom
Mashing it Up in the ClassroomMashing it Up in the Classroom
Mashing it Up in the ClassroomLee-Anne P
 
What 1,000,000 Social Media Experts Taught Me
What 1,000,000 Social Media Experts Taught MeWhat 1,000,000 Social Media Experts Taught Me
What 1,000,000 Social Media Experts Taught MeDylan Wilbanks
 
10 Years In The Hole: A Possibly Cautionary Tale About Being A Higher Ed Web ...
10 Years In The Hole: A Possibly Cautionary Tale About Being A Higher Ed Web ...10 Years In The Hole: A Possibly Cautionary Tale About Being A Higher Ed Web ...
10 Years In The Hole: A Possibly Cautionary Tale About Being A Higher Ed Web ...Dylan Wilbanks
 
Don't Ask How The Sausage Is Made: How To Bring UX Into A Startup Without Goi...
Don't Ask How The Sausage Is Made: How To Bring UX Into A Startup Without Goi...Don't Ask How The Sausage Is Made: How To Bring UX Into A Startup Without Goi...
Don't Ask How The Sausage Is Made: How To Bring UX Into A Startup Without Goi...Dylan Wilbanks
 
Open Web Camp 2014: On Fireproof, Future-Proof, Failure-Proof Things.
Open Web Camp 2014: On Fireproof, Future-Proof, Failure-Proof Things.Open Web Camp 2014: On Fireproof, Future-Proof, Failure-Proof Things.
Open Web Camp 2014: On Fireproof, Future-Proof, Failure-Proof Things.Dylan Wilbanks
 
Learning Technologies B
Learning Technologies BLearning Technologies B
Learning Technologies BLee-Anne P
 
Twin Redheaded Stepchildren of a Different Mother: The Usability of Accessibi...
Twin Redheaded Stepchildren of a Different Mother: The Usability of Accessibi...Twin Redheaded Stepchildren of a Different Mother: The Usability of Accessibi...
Twin Redheaded Stepchildren of a Different Mother: The Usability of Accessibi...Dylan Wilbanks
 
Your Diet Will Fail (And Why Mine Eventually Will
Your Diet Will Fail (And Why Mine Eventually WillYour Diet Will Fail (And Why Mine Eventually Will
Your Diet Will Fail (And Why Mine Eventually WillDylan Wilbanks
 
Maths ict induction aug10
Maths ict induction aug10Maths ict induction aug10
Maths ict induction aug10Lee-Anne P
 
Applied Kanban - Bizcamp 2011
Applied Kanban - Bizcamp 2011Applied Kanban - Bizcamp 2011
Applied Kanban - Bizcamp 2011wonko
 
Making the Web Fireproof: A Building Code for Websites
Making the Web Fireproof: A Building Code for WebsitesMaking the Web Fireproof: A Building Code for Websites
Making the Web Fireproof: A Building Code for WebsitesDylan Wilbanks
 
Craftmanship
CraftmanshipCraftmanship
Craftmanshipwonko
 
Rails hosting
Rails hostingRails hosting
Rails hostingwonko
 
New forest filming
New forest filmingNew forest filming
New forest filmingHydeK
 
Jenna Dhingana Resume 1
Jenna Dhingana Resume 1Jenna Dhingana Resume 1
Jenna Dhingana Resume 1Jenna Dhingana
 
January Monthly Presenation
January Monthly PresenationJanuary Monthly Presenation
January Monthly PresenationBryant Garcia
 
Madeline Shefferly Resume - 10-16
Madeline Shefferly Resume - 10-16Madeline Shefferly Resume - 10-16
Madeline Shefferly Resume - 10-16Madeline Shefferly
 

Andere mochten auch (20)

Lee-Anne - Indiv Researc
Lee-Anne - Indiv ResearcLee-Anne - Indiv Researc
Lee-Anne - Indiv Researc
 
Mashing it Up in the Classroom
Mashing it Up in the ClassroomMashing it Up in the Classroom
Mashing it Up in the Classroom
 
Cybersafety
CybersafetyCybersafety
Cybersafety
 
What 1,000,000 Social Media Experts Taught Me
What 1,000,000 Social Media Experts Taught MeWhat 1,000,000 Social Media Experts Taught Me
What 1,000,000 Social Media Experts Taught Me
 
10 Years In The Hole: A Possibly Cautionary Tale About Being A Higher Ed Web ...
10 Years In The Hole: A Possibly Cautionary Tale About Being A Higher Ed Web ...10 Years In The Hole: A Possibly Cautionary Tale About Being A Higher Ed Web ...
10 Years In The Hole: A Possibly Cautionary Tale About Being A Higher Ed Web ...
 
Don't Ask How The Sausage Is Made: How To Bring UX Into A Startup Without Goi...
Don't Ask How The Sausage Is Made: How To Bring UX Into A Startup Without Goi...Don't Ask How The Sausage Is Made: How To Bring UX Into A Startup Without Goi...
Don't Ask How The Sausage Is Made: How To Bring UX Into A Startup Without Goi...
 
Open Web Camp 2014: On Fireproof, Future-Proof, Failure-Proof Things.
Open Web Camp 2014: On Fireproof, Future-Proof, Failure-Proof Things.Open Web Camp 2014: On Fireproof, Future-Proof, Failure-Proof Things.
Open Web Camp 2014: On Fireproof, Future-Proof, Failure-Proof Things.
 
Learning Technologies B
Learning Technologies BLearning Technologies B
Learning Technologies B
 
Twin Redheaded Stepchildren of a Different Mother: The Usability of Accessibi...
Twin Redheaded Stepchildren of a Different Mother: The Usability of Accessibi...Twin Redheaded Stepchildren of a Different Mother: The Usability of Accessibi...
Twin Redheaded Stepchildren of a Different Mother: The Usability of Accessibi...
 
Your Diet Will Fail (And Why Mine Eventually Will
Your Diet Will Fail (And Why Mine Eventually WillYour Diet Will Fail (And Why Mine Eventually Will
Your Diet Will Fail (And Why Mine Eventually Will
 
Maths ict induction aug10
Maths ict induction aug10Maths ict induction aug10
Maths ict induction aug10
 
Applied Kanban - Bizcamp 2011
Applied Kanban - Bizcamp 2011Applied Kanban - Bizcamp 2011
Applied Kanban - Bizcamp 2011
 
Making the Web Fireproof: A Building Code for Websites
Making the Web Fireproof: A Building Code for WebsitesMaking the Web Fireproof: A Building Code for Websites
Making the Web Fireproof: A Building Code for Websites
 
Everyone Coredumps
Everyone CoredumpsEveryone Coredumps
Everyone Coredumps
 
Craftmanship
CraftmanshipCraftmanship
Craftmanship
 
Rails hosting
Rails hostingRails hosting
Rails hosting
 
New forest filming
New forest filmingNew forest filming
New forest filming
 
Jenna Dhingana Resume 1
Jenna Dhingana Resume 1Jenna Dhingana Resume 1
Jenna Dhingana Resume 1
 
January Monthly Presenation
January Monthly PresenationJanuary Monthly Presenation
January Monthly Presenation
 
Madeline Shefferly Resume - 10-16
Madeline Shefferly Resume - 10-16Madeline Shefferly Resume - 10-16
Madeline Shefferly Resume - 10-16
 

Ähnlich wie Using Mongomapper to store dynamic data

MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Railsrfischer20
 
Mongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-finalMongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-finalMongoDB
 
MongoDB Hadoop DC
MongoDB Hadoop DCMongoDB Hadoop DC
MongoDB Hadoop DCMike Dirolf
 
Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)Chris Richardson
 
MongoDB at Gilt Groupe
MongoDB at Gilt GroupeMongoDB at Gilt Groupe
MongoDB at Gilt GroupeMongoDB
 
MongoDB in FS
MongoDB in FSMongoDB in FS
MongoDB in FSMongoDB
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHPichikaway
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDBNorberto Leite
 
MongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewMongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewAntonio Pintus
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentationOleksii Usyk
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsMongoDB
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!Daniel Cousineau
 
MongoDB EuroPython 2009
MongoDB EuroPython 2009MongoDB EuroPython 2009
MongoDB EuroPython 2009Mike Dirolf
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBMongoDB
 
MongoDB NYC Python
MongoDB NYC PythonMongoDB NYC Python
MongoDB NYC PythonMike Dirolf
 
Learning to run
Learning to runLearning to run
Learning to rundominion
 

Ähnlich wie Using Mongomapper to store dynamic data (20)

MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Rails
 
Mongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-finalMongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-final
 
Rails with mongodb
Rails with mongodbRails with mongodb
Rails with mongodb
 
MongoDB Hadoop DC
MongoDB Hadoop DCMongoDB Hadoop DC
MongoDB Hadoop DC
 
Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)
 
MongoDB at Gilt Groupe
MongoDB at Gilt GroupeMongoDB at Gilt Groupe
MongoDB at Gilt Groupe
 
MongoDB in FS
MongoDB in FSMongoDB in FS
MongoDB in FS
 
MongoDB at RuPy
MongoDB at RuPyMongoDB at RuPy
MongoDB at RuPy
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHP
 
CouchDB introduction
CouchDB introductionCouchDB introduction
CouchDB introduction
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
MongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewMongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overview
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentation
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
 
MongoDB
MongoDBMongoDB
MongoDB
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
 
MongoDB EuroPython 2009
MongoDB EuroPython 2009MongoDB EuroPython 2009
MongoDB EuroPython 2009
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 
MongoDB NYC Python
MongoDB NYC PythonMongoDB NYC Python
MongoDB NYC Python
 
Learning to run
Learning to runLearning to run
Learning to run
 

Kürzlich hochgeladen

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 

Kürzlich hochgeladen (20)

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 

Using Mongomapper to store dynamic data

  • 1. MONGODB AND RUBY Persisting dynamic data with MongoMapper
  • 2.
  • 3. MONGODB • humongous • auto-sharding • Speed!!! • replication and fail-over • document-oriented storage • GridFS (BSON) • MapReduce • dynamic queries • Schemaless • fast, in-place updates
  • 4. USE IT FOR.. • (most) Websites • Caching • Scalabilty
  • 5. SKIP IT FOR.. • Transactions • Lots of joins • Fixed datasets (science,...)
  • 6. START USING IT • MongoDB in google: www.mongodb.org - Quickstart • make a directory • download mongodb • unpack
  • 9. QUERYING > db.fosdem.save({talk: "MongoDB", presenter: "Bernard"}) > db.fosdem.find() { "_id" : ObjectId("4b681a1ecf1bcfea49f4b2ae"), "talk" : "MongoDB", "presenter" : "Bernard" }
  • 10. MORE QUERYING > db.fosdem.find({presenter: "Bernard") { "_id" : ObjectId("4b681a1ecf1bcfea49f4b2ae"), "talk" : "MongoDB", "presenter" : "Bernard" }
  • 12.
  • 13. gem install mongo_mapper gem install mongo_ext
  • 15. class Presenter include MongoMapper::Document end
  • 16. class Presenter include MongoMapper::Document key :name, String key :confirmed, Boolean key :keywords, Array key :presentation, Presentation end
  • 17. presenter = Presenter.new({ :name => “Bernard”, :confirmed => true, :keywords => [“Openminds”, “geek”] }) presenter.save presenter.destroy
  • 19. MONGOMAPPER HAS • validates_* • before_save / after_update / ... • has_many / belongs_to • timestamps!
  • 20. CUSTOM DATATYPES class Keywords class Presenter def initialize(array) include MongoMapper::Document @words = array key :keywords, Keywords end end def to_a @words end class << self def to_mongo(value) value.is_a?(Keyword) ? keyword.to_a : value end def from_mongo(value) value ? self.new(value) : nil end end end
  • 23. INHERITANCE class Page class BlogPost < Page key :permalink, String key :content, String key :title, String has_many :comments end end class Redirect < Page key :destination, String end
  • 24. MODULAR module Authentication def self.included(base) base.key :password, String base.key :salt, String base.key :login, String end end class Person include MongoMapper::Document include Authentication end
  • 25. MULTISITE WEBSHOP EXAMPLE per instance data gathering
  • 26. ORDERS AS A DOCUMENT class Order include MongoMapper::Document key :order_id, String class << self def for_site(site) klass = Class.new(self) klass.order_fields = site.order_fields Object.const_set("OrderForSite#{site.id}", klass) klass end def order_fields=(fields) fields.each do |field| key field, String end end end end
  • 27. ORDERS: MONGOMAPPER class Order include MongoMapper::Document key :order_id, String
  • 28. ORDER: CLASS FOR A SPECIFIC SITE def for_site(site) klass = Class.new(self) klass.order_fields = site.order_fields Object.const_set("OrderForSite#{site.id}", klass) klass end
  • 29. DYNAMIC DOCUMENT BUILDING def order_fields=(fields) fields.each do |field| key field, String end end
  • 30. PER USER class Order include MongoMapper::Document key :order_id, String class << self def for_site(site) klass = Class.new(self) klass.order_fields = site.order_fields Object.const_set("OrderForSite#{site.id}", klass) klass end def order_fields=(fields) fields.each do |field| key field, String end end end end
  • 31. SITE • Can be a Mongo-document • Can be an ActiveRecord object • Can be a (Rails 3) ActiveModel object (REST?) • Has to “respond_to? :id” and “respond_to? :order_fields”
  • 32. TRY IT OUT current_site.order_fields #=> [“field1”, “field2”] @order = Order.for_site(current_site).new #=> #<OrderForSite2172858380 field1: nil, field2: nil, order_id: nil>
  • 33. Q&A
  • 34. 1 2 3 4 5 6 7 • Bernard Grymonpon 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 • Openminds BVBA • Hosting & Rails-shop ribbit • @wonko_be - @openminds_be Top sites deserve maximum uptime openminds.be tailored hosting solutions