SlideShare a Scribd company logo
MongoDB
(from “humongous”)




     Wouter de Vos – 2011-10-31
What is MongoDB?

•   A No-SQL database

•   Document oriented

•   Open Source

•   Written in C++
Document Oriented?

•   Documents are stored in collections   > db.posts.findOne()
                                          {
                                            _id : ObjectId("4e77bb3b8a3e000000004f7a"),
                                            when : Date("2011-09-19T02:10:11.3Z",
                                            author : "alex",


•
                                            title : "No Free Lunch",
    No JOINS: embedded                      text : "This is the text of the post. It could be very long.",
                                            tags : [ "business", "ramblings" ],
                                            votes : 5,
                                            voters : [ "jane", "joe", "spencer", "phyllis", "li" ],
                                            comments : [


•
                                              { who : "jane", when : Date("2011-09-19T04:00:10.112Z"),
    No JOINS: linked                            comment : "I agree." },
                                              { who : "meghan", when : Date("2011-09-20T14:36:06.958Z"),
                                                comment : "You must be joking. etc etc ..." }
                                            ]
                                          }
Document Oriented?

•   Documents are stored in collections   > db.posts.findOne()
                                          {
                                            _id : ObjectId("4e77bb3b8a3e000000004f7a"),
                                            when : Date("2011-09-19T02:10:11.3Z",
                                            author : "alex",


•
                                            title : "No Free Lunch",
    No JOINS: embedded                      text : "This is the text of the post. It could be very long.",
                                            tags : [ "business", "ramblings" ],
                                            votes : 5,
                                            voters : [ "jane", "joe", "spencer", "phyllis", "li" ],
                                            comments : [


•
                                              { who : "jane", when : Date("2011-09-19T04:00:10.112Z"),
    No JOINS: linked                            comment : "I agree." },
                                              { who : "meghan", when : Date("2011-09-20T14:36:06.958Z"),
                                                comment : "You must be joking. etc etc ..." }
                                            ]
                                          }
Document Oriented?

•   Documents are stored in collections
                                                      > db.posts.findOne()


•
                                                      {
    No JOINS: embedded                                  _id : ObjectId("4e77bb3b8a3e000000004f7a"),
                                                        when : Date("2011-09-19T02:10:11.3Z",
                                                        author : "alex",
                                                        title : "No Free Lunch",
                                                        text : "This is the text of the post. It could be very long.",


•
                                                        tags : [ "business", "ramblings" ],
    No JOINS: linked                                    votes : 5,
                                                        voters : [ "jane", "joe", "spencer", "phyllis", "li" ],
                                                        comments : [
                                                          { who : "jane", when : Date("2011-09-19T04:00:10.112Z"),
                                                            comment : "I agree." },


    •
                                                          { who : "meghan", when : Date("2011-09-20T14:36:06.958Z"),
        links are references to other documents and     ]
                                                            comment : "You must be joking. etc etc ..." }

        are processed by the client.                  }
Cool features
                                   > db.invoices.find()
                                   {

•   Schemaless
                                      _id : ObjectId("4e77bb3b8a3e000000004f7a"),
                                      client: "Johnson",
                                      hosting: {
                                         per: "month",


•
                                         price: 100,
    Atomic operations                 },
                                         amount: 12,

                                      development: {
                                         per: "hour",

•   Map/Reduce
                                      }
                                         price: 120,
                                         amount: 80

                                   },

•
                                   {
    Fast, in-place updates            _id : ObjectId("4e77bb3b8a3e000000005f7a"),
                                      client: "Black",
                                      development: {
                                         per: "hour",

•   GridFS
                                      }
                                         price: 120,
                                         amount: 30

                                   },
Cool features
•   Schemaless                     atomically {
                                     if( doc.credits > 5 ) {
                                       doc.credits -= 5;
•   Atomic operations                  doc.debits += 5;
                                     }
                                   }
•   Map/Reduce


•   Fast, in-place updates


•   GridFS
Cool features
                                 // Document example
                                 { username: "jones",
                                   likes: 20,
                                   text: "Hello world!"

•   Schemaless                   }

                                 // Map
                                 function() {

•   Atomic operations            }
                                   emit( this.username, {count: 1, likes: this.likes} );


                                 // Reduce

•
                                 function(key, values) {
    Map/Reduce                     var result = {count: 0, likes: 0};

                                     values.forEach(function(value) {
                                       result.count += value.count;

•   Fast, in-place updates             result.likes += value.likes;
                                     });

                                     return result;

•
                                 }
    GridFS
                                 // Result
                                 { count: 10, likes: 247 }
Cool features
•   Schemaless


•   Atomic operations
                               // In place update
                               db.recipes.update(

•   Map/Reduce
                               )
                                   {'_id': recipe_id, 'voters': {'$ne': user_id}},
                                   {'$inc': {'votes': 1}, '$push': {'voters': user_id}}




•   Fast, in-place updates


•   GridFS
Cool features
•   Schemaless


•   Atomic operations              The GridFS spec provides a mechanism for
                                transparently dividing a large file among multiple

•   Map/Reduce
                               documents. This allows us to efficiently store large
                                objects, and in the case of especially large files,
                                 such as videos, permits range operations (e.g.,
•   Fast, in-place updates           fetching only the first N bytes of a file).


•   GridFS
Querying
• // A post with title “Mongo”
  db.posts.find({'title': 'Mongo'})


• // All posts about tennis, but without comments
  db.posts.find( { tags : 'tennis' }, { comments : 0 } );


• // last 5 comments
  db.posts.find({}, {comments:{'$slice': -5}})


• // just the likes of the comments
  db.posts.find({}, {'comments.$.likes': 1}
Use it for

•   It’s schemaless features (e.g. for prototyping)

•   It’s horizontal scalability (with auto-sharding)

•   To store and stream large files (with gridfs)

•   To make ultra-fast, single query updates
Cucumber
Scenarios for browser testing
Feature: User Registration and Logging in
  A User should be able to create an account.
  A User should be able to log in with a new account.
  A User should be able to create a profile after logging in for the first time.

  Scenario: Registration with a normal account.
    Given I sign up as a new user with email@example.com/secret
    Then I should be signed in
    And I sign out

  Scenario: Log in with a new account
    Given I sign up as a new user with email@example.com/secret
    Then I should be signed in
    Then I sign out
    And I sign in with email@example.com/secret
    Then I should be signed in
    And I sign out

  Scenario: Create a profile with a new account
    Given I sign in as a new user
    Then I should see "create your profile"
    And I fill in "profile_name" with "My Name"
    And I fill in "profile_about" with "I am a long green vegetable that goes well with salads."
    And I select an avatar file
    And I press "Save"
    Then I should see "Profile was successfully updated."
    And I sign out
Step definitions in Ruby
Test Results
Mechanize, Selenium / Webkit


•   Mechanize: fast, but no javascript support

•   Selenium, javascript support, but sloooow

•   Webkit, javascript support, less slooow

More Related Content

What's hot (20)

PDF
Schema design
MongoDB
 
PDF
Learn Learn how to build your mobile back-end with MongoDB
Marakana Inc.
 
KEY
Practical Ruby Projects (Alex Sharp)
MongoSF
 
KEY
Practical Ruby Projects with MongoDB - MongoSF
Alex Sharp
 
PDF
CouchDB at JAOO Århus 2009
Jason Davies
 
PPTX
Advanced Document Modeling Techniques from a High-Scale Commerce Platform
MongoDB
 
KEY
OSCON 2012 MongoDB Tutorial
Steven Francia
 
PPTX
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
PDF
Schema Design
MongoDB
 
KEY
MongoDB at ZPUGDC
Mike Dirolf
 
PDF
Graph Connect: Importing data quickly and easily
Mark Needham
 
PPTX
MongoDC 2012: How MongoDB Powers Doodle or Die
MongoDB
 
KEY
MongoDB and hadoop
Steven Francia
 
PDF
GraphConnect Europe 2016 - Building Spring Data Neo4j 4.1 Applications Like A...
Neo4j
 
PDF
Dealing with Azure Cosmos DB
Mihail Mateev
 
PDF
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
Doris Chen
 
PDF
MongoDB dessi-codemotion
Massimiliano Dessì
 
PDF
MongoDB and Ruby on Rails
rfischer20
 
KEY
MongoDB
Steven Francia
 
PPTX
Mongo or Die: How MongoDB Powers Doodle or Die
Aaron Silverman
 
Schema design
MongoDB
 
Learn Learn how to build your mobile back-end with MongoDB
Marakana Inc.
 
Practical Ruby Projects (Alex Sharp)
MongoSF
 
Practical Ruby Projects with MongoDB - MongoSF
Alex Sharp
 
CouchDB at JAOO Århus 2009
Jason Davies
 
Advanced Document Modeling Techniques from a High-Scale Commerce Platform
MongoDB
 
OSCON 2012 MongoDB Tutorial
Steven Francia
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
Schema Design
MongoDB
 
MongoDB at ZPUGDC
Mike Dirolf
 
Graph Connect: Importing data quickly and easily
Mark Needham
 
MongoDC 2012: How MongoDB Powers Doodle or Die
MongoDB
 
MongoDB and hadoop
Steven Francia
 
GraphConnect Europe 2016 - Building Spring Data Neo4j 4.1 Applications Like A...
Neo4j
 
Dealing with Azure Cosmos DB
Mihail Mateev
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
Doris Chen
 
MongoDB dessi-codemotion
Massimiliano Dessì
 
MongoDB and Ruby on Rails
rfischer20
 
Mongo or Die: How MongoDB Powers Doodle or Die
Aaron Silverman
 

Viewers also liked (20)

PDF
Identifying Antibiotics posing potential Health Risk: Microbial Resistance Sc...
Atai Rabby
 
PPTX
Tipos de biblioteca
Vanesa Ovin
 
PPT
Rph Ringkas
Rafidah Diah
 
PPSX
Анимационный ролик мир вокруг нас
Марина Д
 
PDF
Expectativas turismo-2016-informe
Turistenístico
 
PPTX
The new comers
irongate55
 
PPTX
Community health & wellness fest 2015
Mary Phillips
 
PPTX
кораблик
Марина Д
 
PDF
Pdf slide show
yawarete
 
PPTX
L
JW18260
 
PPT
Presentatie2 versie2b
verenigingoudvriezenveen
 
PPTX
Small Biz CEDC Orientation
Mary Phillips
 
ODP
Tweaking Open Source
Nelson Gomes
 
PDF
Cinco claves de los mercados hoteleros de Madrid y Barcelona 2016
Turistenístico
 
PDF
Don't Write Them Off, Cast Iron Boilers Still Have a Future
BuildingMech
 
PPT
Gaya gerak listrik
Andhryn Celica
 
PPTX
台北國際烘焙暨設備展New
EVERY8D 許
 
PDF
The Future of Travel in 2020
Turistenístico
 
PPTX
Small biz expo & suit donation for the homeless
Mary Phillips
 
Identifying Antibiotics posing potential Health Risk: Microbial Resistance Sc...
Atai Rabby
 
Tipos de biblioteca
Vanesa Ovin
 
Rph Ringkas
Rafidah Diah
 
Анимационный ролик мир вокруг нас
Марина Д
 
Expectativas turismo-2016-informe
Turistenístico
 
The new comers
irongate55
 
Community health & wellness fest 2015
Mary Phillips
 
кораблик
Марина Д
 
Pdf slide show
yawarete
 
Presentatie2 versie2b
verenigingoudvriezenveen
 
Small Biz CEDC Orientation
Mary Phillips
 
Tweaking Open Source
Nelson Gomes
 
Cinco claves de los mercados hoteleros de Madrid y Barcelona 2016
Turistenístico
 
Don't Write Them Off, Cast Iron Boilers Still Have a Future
BuildingMech
 
Gaya gerak listrik
Andhryn Celica
 
台北國際烘焙暨設備展New
EVERY8D 許
 
The Future of Travel in 2020
Turistenístico
 
Small biz expo & suit donation for the homeless
Mary Phillips
 
Ad

Similar to Springest Dev Lunch: MongoDB Introduction (20)

KEY
Introduction to MongoDB
Neil Henegan
 
PDF
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
Johannes Hoppe
 
KEY
Schema Design by Example ~ MongoSF 2012
hungarianhc
 
KEY
2011 mongo sf-schemadesign
MongoDB
 
KEY
2012 phoenix mug
Paul Pedersen
 
PDF
2013-03-23 - NoSQL Spartakiade
Johannes Hoppe
 
KEY
MongoDB
Steve Klabnik
 
PDF
MongoDB at FrozenRails
Mike Dirolf
 
PDF
The emerging world of mongo db csp
Carlos Sánchez Pérez
 
PDF
SQL? NoSQL? NewSQL?!? What's a Java developer to do? - PhillyETE 2012
Chris Richardson
 
PDF
Latinoware
kchodorow
 
PPTX
MongoDB Schema Design: Four Real-World Examples
Mike Friedman
 
PPTX
MongoDB Schema Design: Four Real-World Examples
Lewis Lin 🦊
 
PDF
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
MongoSF
 
PPTX
Data Modeling Deep Dive
MongoDB
 
PDF
Mongo db
Antonio Terreno
 
PPTX
MongoDB London 2013: Data Modeling Examples from the Real World presented by ...
MongoDB
 
PDF
Persisting dynamic data with mongodb and mongomapper
wonko
 
KEY
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Alex Nguyen
 
KEY
Schema Design with MongoDB
rogerbodamer
 
Introduction to MongoDB
Neil Henegan
 
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
Johannes Hoppe
 
Schema Design by Example ~ MongoSF 2012
hungarianhc
 
2011 mongo sf-schemadesign
MongoDB
 
2012 phoenix mug
Paul Pedersen
 
2013-03-23 - NoSQL Spartakiade
Johannes Hoppe
 
MongoDB
Steve Klabnik
 
MongoDB at FrozenRails
Mike Dirolf
 
The emerging world of mongo db csp
Carlos Sánchez Pérez
 
SQL? NoSQL? NewSQL?!? What's a Java developer to do? - PhillyETE 2012
Chris Richardson
 
Latinoware
kchodorow
 
MongoDB Schema Design: Four Real-World Examples
Mike Friedman
 
MongoDB Schema Design: Four Real-World Examples
Lewis Lin 🦊
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
MongoSF
 
Data Modeling Deep Dive
MongoDB
 
Mongo db
Antonio Terreno
 
MongoDB London 2013: Data Modeling Examples from the Real World presented by ...
MongoDB
 
Persisting dynamic data with mongodb and mongomapper
wonko
 
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Alex Nguyen
 
Schema Design with MongoDB
rogerbodamer
 
Ad

Recently uploaded (20)

PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 

Springest Dev Lunch: MongoDB Introduction

  • 1. MongoDB (from “humongous”) Wouter de Vos – 2011-10-31
  • 2. What is MongoDB? • A No-SQL database • Document oriented • Open Source • Written in C++
  • 3. Document Oriented? • Documents are stored in collections > db.posts.findOne() { _id : ObjectId("4e77bb3b8a3e000000004f7a"), when : Date("2011-09-19T02:10:11.3Z", author : "alex", • title : "No Free Lunch", No JOINS: embedded text : "This is the text of the post. It could be very long.", tags : [ "business", "ramblings" ], votes : 5, voters : [ "jane", "joe", "spencer", "phyllis", "li" ], comments : [ • { who : "jane", when : Date("2011-09-19T04:00:10.112Z"), No JOINS: linked comment : "I agree." }, { who : "meghan", when : Date("2011-09-20T14:36:06.958Z"), comment : "You must be joking. etc etc ..." } ] }
  • 4. Document Oriented? • Documents are stored in collections > db.posts.findOne() { _id : ObjectId("4e77bb3b8a3e000000004f7a"), when : Date("2011-09-19T02:10:11.3Z", author : "alex", • title : "No Free Lunch", No JOINS: embedded text : "This is the text of the post. It could be very long.", tags : [ "business", "ramblings" ], votes : 5, voters : [ "jane", "joe", "spencer", "phyllis", "li" ], comments : [ • { who : "jane", when : Date("2011-09-19T04:00:10.112Z"), No JOINS: linked comment : "I agree." }, { who : "meghan", when : Date("2011-09-20T14:36:06.958Z"), comment : "You must be joking. etc etc ..." } ] }
  • 5. Document Oriented? • Documents are stored in collections > db.posts.findOne() • { No JOINS: embedded _id : ObjectId("4e77bb3b8a3e000000004f7a"), when : Date("2011-09-19T02:10:11.3Z", author : "alex", title : "No Free Lunch", text : "This is the text of the post. It could be very long.", • tags : [ "business", "ramblings" ], No JOINS: linked votes : 5, voters : [ "jane", "joe", "spencer", "phyllis", "li" ], comments : [ { who : "jane", when : Date("2011-09-19T04:00:10.112Z"), comment : "I agree." }, • { who : "meghan", when : Date("2011-09-20T14:36:06.958Z"), links are references to other documents and ] comment : "You must be joking. etc etc ..." } are processed by the client. }
  • 6. Cool features > db.invoices.find() { • Schemaless _id : ObjectId("4e77bb3b8a3e000000004f7a"), client: "Johnson", hosting: { per: "month", • price: 100, Atomic operations }, amount: 12, development: { per: "hour", • Map/Reduce } price: 120, amount: 80 }, • { Fast, in-place updates _id : ObjectId("4e77bb3b8a3e000000005f7a"), client: "Black", development: { per: "hour", • GridFS } price: 120, amount: 30 },
  • 7. Cool features • Schemaless atomically { if( doc.credits > 5 ) { doc.credits -= 5; • Atomic operations doc.debits += 5; } } • Map/Reduce • Fast, in-place updates • GridFS
  • 8. Cool features // Document example { username: "jones", likes: 20, text: "Hello world!" • Schemaless } // Map function() { • Atomic operations } emit( this.username, {count: 1, likes: this.likes} ); // Reduce • function(key, values) { Map/Reduce var result = {count: 0, likes: 0}; values.forEach(function(value) { result.count += value.count; • Fast, in-place updates result.likes += value.likes; }); return result; • } GridFS // Result { count: 10, likes: 247 }
  • 9. Cool features • Schemaless • Atomic operations // In place update db.recipes.update( • Map/Reduce ) {'_id': recipe_id, 'voters': {'$ne': user_id}}, {'$inc': {'votes': 1}, '$push': {'voters': user_id}} • Fast, in-place updates • GridFS
  • 10. Cool features • Schemaless • Atomic operations The GridFS spec provides a mechanism for transparently dividing a large file among multiple • Map/Reduce documents. This allows us to efficiently store large objects, and in the case of especially large files, such as videos, permits range operations (e.g., • Fast, in-place updates fetching only the first N bytes of a file). • GridFS
  • 11. Querying • // A post with title “Mongo” db.posts.find({'title': 'Mongo'}) • // All posts about tennis, but without comments db.posts.find( { tags : 'tennis' }, { comments : 0 } ); • // last 5 comments db.posts.find({}, {comments:{'$slice': -5}}) • // just the likes of the comments db.posts.find({}, {'comments.$.likes': 1}
  • 12. Use it for • It’s schemaless features (e.g. for prototyping) • It’s horizontal scalability (with auto-sharding) • To store and stream large files (with gridfs) • To make ultra-fast, single query updates
  • 14. Scenarios for browser testing Feature: User Registration and Logging in A User should be able to create an account. A User should be able to log in with a new account. A User should be able to create a profile after logging in for the first time. Scenario: Registration with a normal account. Given I sign up as a new user with [email protected]/secret Then I should be signed in And I sign out Scenario: Log in with a new account Given I sign up as a new user with [email protected]/secret Then I should be signed in Then I sign out And I sign in with [email protected]/secret Then I should be signed in And I sign out Scenario: Create a profile with a new account Given I sign in as a new user Then I should see "create your profile" And I fill in "profile_name" with "My Name" And I fill in "profile_about" with "I am a long green vegetable that goes well with salads." And I select an avatar file And I press "Save" Then I should see "Profile was successfully updated." And I sign out
  • 17. Mechanize, Selenium / Webkit • Mechanize: fast, but no javascript support • Selenium, javascript support, but sloooow • Webkit, javascript support, less slooow

Editor's Notes