SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von Jonathan Holloway

Mehr von 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
 

Kürzlich hochgeladen

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
 
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
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
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
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
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
 
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
 
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
 
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
 

Kürzlich hochgeladen (20)

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
 
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
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
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
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
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
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
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
 
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
 

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