SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
with Ruby and MongoMapper
What's the presentation about?
To provide a basic introduction to MongoDB
An introduction to the MongoMapper Ruby
gem and how easy, readable the code is for
persisting/querying MongoDB
Caveat - “I’ve spent a few weeks learning about
this with Ruby and MongoMapper”
What the heck is MongoDB?
JSON (actually BSON - binary) based
datastore with 16MB document limit
Written in C++
Distros on Linux (RPM), OSX (Brew)
Lots of different language drivers available
(Ruby, R, Erlang, Python)
Why would I use it?
Simplicity - Building Javascript applications
without the layers of translation between
presentation -> business logic -> data access
Scaling out - rapidly without the hassle of
sharded MySQL or Postgres with Slony.
100GB+ on a single instance.
“It's quick to develop against - this is what I
want to use it for, prototyping!”
What’s Similar
CouchDB - although your datastore has to be
hardcoded up front in terms of views.
● It’s hard to do query filtering etc...
● Have to query through MapReduce JS
Who Uses MongoDB?
● Craigslist (Everybody uses it in North
America instead of Ebay)
● SAP - SaaS based platform
● MTV
● Sourceforge - backend storage
● Firebase (Datastore as a Service)
https://www.firebase.com
Mental Mapping
Table = Collection
Row = JSON Document
Index = Index
Join = Embedded Document
Partition = Shard
Partition Key = Shard Key
Useful Comparison Document
http://docs.mongodb.org/manual/reference/sql-comparison/
There's lots of API's including a native
MongoDB REST API, but...
I'm going to use:
● Ruby 1.9
● MongoMapper Gem
● ruby-mongo-driver (well the gem is)
Simple Storage Example
Install the gems for MongoMapper
gem install mongo_mapper
gem install bson_ext
or put the following in your Gemfile and use
bundler (http://bundler.io/):
source "https://rubygems.org"
gem "mongo_mapper"
gem "mongomapper_search"
Pre-requisites
Use mongod to start the database:
mongod --rest --dbpath=/home/jholloway/mongodb
Starting MongoDB
Native Port
Used by the MongoDB driver - in my case the
MongoMapper gem interacts with this
http://127.0.0.1:27017
Web UI
Allows us to inspect the MongoDB
http://127.0.0.1:28017
There's also a Mongo interactive shell (mongo)
MongoDB Interfaces
● I've got a number of ebay items I want to
store, specifically some retro computer
games I’m tracking prices of on Ebay
Overview
MongoMapper: Create a Document
Specify the ebay item definition using the
MongoMapper API
class Item
include MongoMapper::Document
key :name, String, :required => true
key :location, String
key :price, Float
end
MongoMapper: Save Document
Create a new item (n.b. use of Ruby symbols)
and call save on it
Item.new(:name => "Rescue from Fractalus",
:platform => "Commodore 64",
:location => "Chippenham",
:price => 2.50).save()
● Let's go back to the Mongo shell
./mongo
show dbs
use myebayitems
show collections
db.items.find()
Mongo Shell: Raw Storage
MongoMapper: Querying Documents
Will use irb for the examples here
irb -r ebayitemsave.rb
Find all items in the collection Item:
items = Item.all()
Query all items by price > 5
items = Item.all( :price => {:$gt => 5} )
MongoMapper: Dynamic Finders
I can also use dynamic finders using the fields
defined on my document, awesomeness.
So in the previous example find by price...
Item.find_by_price(2.50)
puts "Item: #{item.to_mongo()}"
MongoMapper: Embedded Docs
Joins - deeply nested JSON documents can be
a performance issue though
Need to think about database design carefully
up-front and model it as you’d expect to query it
This is very different from a relational database
with a reporting backend
http://mongomapper.com/documentation/
MongoMapper: MapReduce Example
MongoDB provides an aggregation framework
for simple operations
It also provides a mapReduce() command
which you can pass Javascript (yes) to the
embedded V8 engine
n.b. Dispatches the command to each shard in
a sharded MongoDB setup
MongoMapper: Full Text Search
Bah !
You can do it!
MongoMapper Search Gem - didn’t work for me
https://github.com/mariopeixoto/mongomapper_search
MongoMapper: Plugins
Fair few of them and you can write your own
easily enough:
● Associations
● Accessible
● Callbacks
● Dirty
● Keys
● Modifiers
● Protected
● Scopes
● Serialization
● Single Collection Inheritance
● Timestamps
● Userstamps
● Validations
MongoMapper: In Retrospect
I’ve just broken the surface with the capabilities
of it in the past few weeks and here
Lots more investigation required into the
aggregation framework and the map reduce
functionality
But it’s much much better than CouchDB for
what I wanted to do
Questions
Thanks!
All the code will be up here in a Github project:
https://github.com/jph98/ebaymongo
By the way we’re hiring...
● Javascript/Java Developers
● Devops
● R Consultants
Email: careers@mango-solutions.com

Contenu connexe

Tendances

appborg, coffeesurgeon, moof, logging-system
appborg, coffeesurgeon, moof, logging-systemappborg, coffeesurgeon, moof, logging-system
appborg, coffeesurgeon, moof, logging-systemendian7000
 
Node.js for Rubists
Node.js for RubistsNode.js for Rubists
Node.js for RubistsSagiv Ofek
 
Pavel Prischepa.node load without-restrictions.DrupalCamp Kiev 2011
Pavel Prischepa.node load without-restrictions.DrupalCamp Kiev 2011Pavel Prischepa.node load without-restrictions.DrupalCamp Kiev 2011
Pavel Prischepa.node load without-restrictions.DrupalCamp Kiev 2011camp_drupal_ua
 
A slightly advanced introduction to node.js
A slightly advanced introduction to node.jsA slightly advanced introduction to node.js
A slightly advanced introduction to node.jsSudar Muthu
 
Brubeck: The Lightning Talk
Brubeck: The Lightning TalkBrubeck: The Lightning Talk
Brubeck: The Lightning TalkJames Dennis
 

Tendances (7)

appborg, coffeesurgeon, moof, logging-system
appborg, coffeesurgeon, moof, logging-systemappborg, coffeesurgeon, moof, logging-system
appborg, coffeesurgeon, moof, logging-system
 
Node.js for Rubists
Node.js for RubistsNode.js for Rubists
Node.js for Rubists
 
Node36
Node36Node36
Node36
 
Pavel Prischepa.node load without-restrictions.DrupalCamp Kiev 2011
Pavel Prischepa.node load without-restrictions.DrupalCamp Kiev 2011Pavel Prischepa.node load without-restrictions.DrupalCamp Kiev 2011
Pavel Prischepa.node load without-restrictions.DrupalCamp Kiev 2011
 
A slightly advanced introduction to node.js
A slightly advanced introduction to node.jsA slightly advanced introduction to node.js
A slightly advanced introduction to node.js
 
Mongo db intro new
Mongo db intro newMongo db intro new
Mongo db intro new
 
Brubeck: The Lightning Talk
Brubeck: The Lightning TalkBrubeck: The Lightning Talk
Brubeck: The Lightning Talk
 

En vedette

Artikel Leon Harinck (TriFinance) ControllersMagazine januari 2013: 'Nieuwe w...
Artikel Leon Harinck (TriFinance) ControllersMagazine januari 2013: 'Nieuwe w...Artikel Leon Harinck (TriFinance) ControllersMagazine januari 2013: 'Nieuwe w...
Artikel Leon Harinck (TriFinance) ControllersMagazine januari 2013: 'Nieuwe w...TriFinance Nederland
 
Open Source & Open Cloud: Why License Is Important
Open Source & Open Cloud: Why License Is ImportantOpen Source & Open Cloud: Why License Is Important
Open Source & Open Cloud: Why License Is ImportantKrishnan Subramanian
 
Social Business Case Study - Enterasys Networks
Social Business Case Study - Enterasys NetworksSocial Business Case Study - Enterasys Networks
Social Business Case Study - Enterasys NetworksKrishnan Subramanian
 
Research Report: Cloud Trends in 2011 and beyond
Research Report: Cloud Trends in 2011 and beyondResearch Report: Cloud Trends in 2011 and beyond
Research Report: Cloud Trends in 2011 and beyondKrishnan Subramanian
 
MongoDB Mojo: Building a Basic Perl App
MongoDB Mojo: Building a Basic Perl AppMongoDB Mojo: Building a Basic Perl App
MongoDB Mojo: Building a Basic Perl AppStennie Steneker
 
Building The Pillars Of Modern Enterprise
Building The Pillars Of Modern EnterpriseBuilding The Pillars Of Modern Enterprise
Building The Pillars Of Modern EnterpriseKrishnan Subramanian
 

En vedette (8)

Cloud Computing And You
Cloud Computing And YouCloud Computing And You
Cloud Computing And You
 
Artikel Leon Harinck (TriFinance) ControllersMagazine januari 2013: 'Nieuwe w...
Artikel Leon Harinck (TriFinance) ControllersMagazine januari 2013: 'Nieuwe w...Artikel Leon Harinck (TriFinance) ControllersMagazine januari 2013: 'Nieuwe w...
Artikel Leon Harinck (TriFinance) ControllersMagazine januari 2013: 'Nieuwe w...
 
Open Source & Open Cloud: Why License Is Important
Open Source & Open Cloud: Why License Is ImportantOpen Source & Open Cloud: Why License Is Important
Open Source & Open Cloud: Why License Is Important
 
Social Business Case Study - Enterasys Networks
Social Business Case Study - Enterasys NetworksSocial Business Case Study - Enterasys Networks
Social Business Case Study - Enterasys Networks
 
Research Report: Cloud Trends in 2011 and beyond
Research Report: Cloud Trends in 2011 and beyondResearch Report: Cloud Trends in 2011 and beyond
Research Report: Cloud Trends in 2011 and beyond
 
MongoDB Mojo: Building a Basic Perl App
MongoDB Mojo: Building a Basic Perl AppMongoDB Mojo: Building a Basic Perl App
MongoDB Mojo: Building a Basic Perl App
 
The Magnet Journey
The Magnet JourneyThe Magnet Journey
The Magnet Journey
 
Building The Pillars Of Modern Enterprise
Building The Pillars Of Modern EnterpriseBuilding The Pillars Of Modern Enterprise
Building The Pillars Of Modern Enterprise
 

Similaire à Introduction to using MongoDB with Ruby

Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBMongoDB
 
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBBedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBTobias Trelle
 
Mongo db first steps with csharp
Mongo db first steps with csharpMongo db first steps with csharp
Mongo db first steps with csharpSerdar Buyuktemiz
 
The elephant in the room mongo db + hadoop
The elephant in the room  mongo db + hadoopThe elephant in the room  mongo db + hadoop
The elephant in the room mongo db + hadoopiammutex
 
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.jsGetting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.jsGrant Goodale
 
MongoDB Introduction, Installation & Execution
MongoDB Introduction, Installation & ExecutionMongoDB Introduction, Installation & Execution
MongoDB Introduction, Installation & ExecutioniFour Technolab Pvt. Ltd.
 
Mongo db bangalore
Mongo db bangaloreMongo db bangalore
Mongo db bangaloreMongoDB
 
Node Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js TutorialNode Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js TutorialPHP Support
 
Rapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and PythonRapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and PythonRick Copeland
 
Mongodb
MongodbMongodb
Mongodbfoliba
 
MongoDB Tokyo - Monitoring and Queueing
MongoDB Tokyo - Monitoring and QueueingMongoDB Tokyo - Monitoring and Queueing
MongoDB Tokyo - Monitoring and QueueingBoxed Ice
 
Mongo db transcript
Mongo db transcriptMongo db transcript
Mongo db transcriptfoliba
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB Habilelabs
 
Analytical data processing
Analytical data processingAnalytical data processing
Analytical data processingPolad Saruxanov
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBTobias Trelle
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsMongoDB
 

Similaire à Introduction to using MongoDB with Ruby (20)

Mongodb
MongodbMongodb
Mongodb
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBBedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
 
Rails with mongodb
Rails with mongodbRails with mongodb
Rails with mongodb
 
Mongo db first steps with csharp
Mongo db first steps with csharpMongo db first steps with csharp
Mongo db first steps with csharp
 
The elephant in the room mongo db + hadoop
The elephant in the room  mongo db + hadoopThe elephant in the room  mongo db + hadoop
The elephant in the room mongo db + hadoop
 
Getting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.jsGetting Started with MongoDB and Node.js
Getting Started with MongoDB and Node.js
 
MongoDB Introduction, Installation & Execution
MongoDB Introduction, Installation & ExecutionMongoDB Introduction, Installation & Execution
MongoDB Introduction, Installation & Execution
 
Mongodb (1)
Mongodb (1)Mongodb (1)
Mongodb (1)
 
Mongo db bangalore
Mongo db bangaloreMongo db bangalore
Mongo db bangalore
 
MongoDB and Node.js
MongoDB and Node.jsMongoDB and Node.js
MongoDB and Node.js
 
Node Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js TutorialNode Js, AngularJs and Express Js Tutorial
Node Js, AngularJs and Express Js Tutorial
 
Rapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and PythonRapid, Scalable Web Development with MongoDB, Ming, and Python
Rapid, Scalable Web Development with MongoDB, Ming, and Python
 
Mongodb
MongodbMongodb
Mongodb
 
MongoDB Tokyo - Monitoring and Queueing
MongoDB Tokyo - Monitoring and QueueingMongoDB Tokyo - Monitoring and Queueing
MongoDB Tokyo - Monitoring and Queueing
 
Mongo db transcript
Mongo db transcriptMongo db transcript
Mongo db transcript
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
Analytical data processing
Analytical data processingAnalytical data processing
Analytical data processing
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 
Webinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.jsWebinar: Building Your First App in Node.js
Webinar: Building Your First App in Node.js
 

Plus de Jonathan Holloway

Plus de Jonathan Holloway (11)

The Role of the Architect
The Role of the ArchitectThe Role of the Architect
The Role of the Architect
 
Spring boot - an introduction
Spring boot - an introductionSpring boot - an introduction
Spring boot - an introduction
 
Jenkins CI presentation
Jenkins CI presentationJenkins CI presentation
Jenkins CI presentation
 
Mockito intro
Mockito introMockito intro
Mockito intro
 
Debugging
DebuggingDebugging
Debugging
 
SOLID principles
SOLID principlesSOLID principles
SOLID principles
 
Application design for the cloud using AWS
Application design for the cloud using AWSApplication design for the cloud using AWS
Application design for the cloud using AWS
 
Building data pipelines
Building data pipelinesBuilding data pipelines
Building data pipelines
 
Introduction to JVM languages and Fantom (very brief)
Introduction to JVM languages and Fantom (very brief)Introduction to JVM languages and Fantom (very brief)
Introduction to JVM languages and Fantom (very brief)
 
Database migration with flyway
Database migration  with flywayDatabase migration  with flyway
Database migration with flyway
 
Lightweight web frameworks
Lightweight web frameworksLightweight web frameworks
Lightweight web frameworks
 

Dernier

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
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
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
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
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
"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
 
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
 
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
 
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
 
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
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
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
 

Dernier (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
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 ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
"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 ...
 
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...
 
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
 
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
 
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
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

Introduction to using MongoDB with Ruby

  • 1. with Ruby and MongoMapper
  • 2. What's the presentation about? To provide a basic introduction to MongoDB An introduction to the MongoMapper Ruby gem and how easy, readable the code is for persisting/querying MongoDB Caveat - “I’ve spent a few weeks learning about this with Ruby and MongoMapper”
  • 3. What the heck is MongoDB? JSON (actually BSON - binary) based datastore with 16MB document limit Written in C++ Distros on Linux (RPM), OSX (Brew) Lots of different language drivers available (Ruby, R, Erlang, Python)
  • 4. Why would I use it? Simplicity - Building Javascript applications without the layers of translation between presentation -> business logic -> data access Scaling out - rapidly without the hassle of sharded MySQL or Postgres with Slony. 100GB+ on a single instance. “It's quick to develop against - this is what I want to use it for, prototyping!”
  • 5. What’s Similar CouchDB - although your datastore has to be hardcoded up front in terms of views. ● It’s hard to do query filtering etc... ● Have to query through MapReduce JS
  • 6. Who Uses MongoDB? ● Craigslist (Everybody uses it in North America instead of Ebay) ● SAP - SaaS based platform ● MTV ● Sourceforge - backend storage ● Firebase (Datastore as a Service) https://www.firebase.com
  • 7. Mental Mapping Table = Collection Row = JSON Document Index = Index Join = Embedded Document Partition = Shard Partition Key = Shard Key Useful Comparison Document http://docs.mongodb.org/manual/reference/sql-comparison/
  • 8. There's lots of API's including a native MongoDB REST API, but... I'm going to use: ● Ruby 1.9 ● MongoMapper Gem ● ruby-mongo-driver (well the gem is) Simple Storage Example
  • 9. Install the gems for MongoMapper gem install mongo_mapper gem install bson_ext or put the following in your Gemfile and use bundler (http://bundler.io/): source "https://rubygems.org" gem "mongo_mapper" gem "mongomapper_search" Pre-requisites
  • 10. Use mongod to start the database: mongod --rest --dbpath=/home/jholloway/mongodb Starting MongoDB
  • 11. Native Port Used by the MongoDB driver - in my case the MongoMapper gem interacts with this http://127.0.0.1:27017 Web UI Allows us to inspect the MongoDB http://127.0.0.1:28017 There's also a Mongo interactive shell (mongo) MongoDB Interfaces
  • 12. ● I've got a number of ebay items I want to store, specifically some retro computer games I’m tracking prices of on Ebay Overview
  • 13. MongoMapper: Create a Document Specify the ebay item definition using the MongoMapper API class Item include MongoMapper::Document key :name, String, :required => true key :location, String key :price, Float end
  • 14. MongoMapper: Save Document Create a new item (n.b. use of Ruby symbols) and call save on it Item.new(:name => "Rescue from Fractalus", :platform => "Commodore 64", :location => "Chippenham", :price => 2.50).save()
  • 15. ● Let's go back to the Mongo shell ./mongo show dbs use myebayitems show collections db.items.find() Mongo Shell: Raw Storage
  • 16. MongoMapper: Querying Documents Will use irb for the examples here irb -r ebayitemsave.rb Find all items in the collection Item: items = Item.all() Query all items by price > 5 items = Item.all( :price => {:$gt => 5} )
  • 17. MongoMapper: Dynamic Finders I can also use dynamic finders using the fields defined on my document, awesomeness. So in the previous example find by price... Item.find_by_price(2.50) puts "Item: #{item.to_mongo()}"
  • 18. MongoMapper: Embedded Docs Joins - deeply nested JSON documents can be a performance issue though Need to think about database design carefully up-front and model it as you’d expect to query it This is very different from a relational database with a reporting backend http://mongomapper.com/documentation/
  • 19. MongoMapper: MapReduce Example MongoDB provides an aggregation framework for simple operations It also provides a mapReduce() command which you can pass Javascript (yes) to the embedded V8 engine n.b. Dispatches the command to each shard in a sharded MongoDB setup
  • 20. MongoMapper: Full Text Search Bah ! You can do it! MongoMapper Search Gem - didn’t work for me https://github.com/mariopeixoto/mongomapper_search
  • 21. MongoMapper: Plugins Fair few of them and you can write your own easily enough: ● Associations ● Accessible ● Callbacks ● Dirty ● Keys ● Modifiers ● Protected ● Scopes ● Serialization ● Single Collection Inheritance ● Timestamps ● Userstamps ● Validations
  • 22. MongoMapper: In Retrospect I’ve just broken the surface with the capabilities of it in the past few weeks and here Lots more investigation required into the aggregation framework and the map reduce functionality But it’s much much better than CouchDB for what I wanted to do
  • 23. Questions Thanks! All the code will be up here in a Github project: https://github.com/jph98/ebaymongo
  • 24. By the way we’re hiring... ● Javascript/Java Developers ● Devops ● R Consultants Email: careers@mango-solutions.com