SlideShare a Scribd company logo
MongoDB and Spring Data
                                                                 Chris Harris
                                                            Twitter : cj_harris5
                                                         Email : charris@10gen.com



© 2012 SpringOne 2GX. All rights reserved. Do not distribute without permission.
About Me

     Solution Architect at 10gen (the company behind MongoDB)




- Previous Roles:
  • EMEA Architect at SpringSource
  • EMEA Principal JBoss Consultant at RedHat



22
http://images.mirror.co.uk/upl/m4/mar2009/0/2/satnav-cliff-hanger-pic-ross-parry-
                             image-3-213726463.jpg
http://www.simpleadhdexpert.com/wp-content/uploads/2009/08/frustration.jpg
http://daddytypes.com/archive/duct_tape_baby_mianro.jpg
Is there a better way?
Terminology

RDBMS           MongoDB
Table           Collection
Row(s)          JSON Document
Index           Index
Join            Embedding & Linking
Partition       Shard
Partition Key   Shard Key
As simple as possible, but no simpler

                            Memcached
                               Key / Value
Scalability & Performance


                                                               MongoDB




                                                                    RDBMS




                                      Depth of functionality
Lets build a Spring Data MongoDB App!
Welcome to Dev News
• User Story 1:
 – As a user I should be able to create “News Articles”
What is a News Article?
{
    title: “What is new in 2.2 MongoDB”,
    date : new Date(),
    author : “Fred”
    text : “.......”
}
Example 1 - Create
Welcome to MongoDB News Dev
• User Story 1:
 – As a user I should be able to create “News Articles”
• User Story 2:
 – As a user I should be able to find a “News Articles” by Name
Example 2 - Query
Example 3 - Repo
Welcome to MongoDB News Dev
• User Story 1:
 – As a user I should be able to create “News Articles”
• User Story 2:
 – As a user I should be able to find a “News Articles” by Name
• User Story 3:
 – As a user I should be able to comment on “News Articles”
What is a Comment?
{
     title: “What is new in 2.2 MongoDB”,
     date : new Date(),
     author : “Fred”
     text : “.......”
     tags : [“mongodb”, “nosql”]
     comments : [
          {author : “chris”, text: “this is great” , date : new Date()},
          {author : “tom”, text: “rock on”, date : new Date()}
    ]
}
Example 4 - Comments
Welcome to MongoDB News Dev
• User Story 1:
 – As a user I should be able to create “News Articles”
• User Story 2:
 – As a user I should be able to find a “News Articles” by Name
• User Story 3:
 – As a user I should be able to comment on “News Articles”
• User Story 4:
 –As a user I want to know how many comments are on a “Articles”
What is a Comment?
{
     title: “What is new in 2.2 MongoDB”,
     ....
     comments : [
          {author : “chris”, text: “this is great” , date : new Date()},
          {author : “tom”, text: “rock on”, date : new Date()}
    ],
    comments: count : 2
}
Example 5 - Inc
“MongoDB lost my data!!”
Data: 125647383885969795743
Least durability - Don't use!
            Driver           MongoDB
                     write

                                  apply in memory
Wait for Journal Sync - Same as RDBMS
           Driver            MongoDB
                    write

                                   apply in memory
                    j:true
                                    Write to journal
Replication




              http://www.flickr.com/photos/10335017@N07/4570943043
Replica Set
•   Data Protection
•   Multiple copies of the data
•   Spread across Data Centers, AZs
•   High Availability
•   Automated Failover
•   Automated Recovery
Replica Sets

             Write
                      Primary
                                 Asynchronous Replication
             Read

  Java App           Secondary



                     Secondary
Replica Sets

             Write
                      Primary
             Read

  Java App           Secondary



                     Secondary
Replica Sets


                       Primary


             Write               Automatic Election of new
  Java App           Primary     Primary
             Read

                     Secondary
Replica Sets


                     Recovering


             Write                New primary serves data
  Java App           Primary
             Read

                     Secondary
Replica Sets


                     Secondary


             Write
  Java App            Primary
             Read

                     Secondary
Durability Summary                               Other Data
                  Memory   Journal   Secondary    Center
  RDBMS

    Default
"Fire & Forget"

   w=1

   w=1
  j=true
w="majority"
   w=n
w="myTag"

         Less                                           More
Example 6 - Write Concern
Eventual Consistency




•            http://www.flickr.com/photos/26095468@N04/3779692985
Understanding Eventual Consistency
     Thread #1   Primary   Secondary

      Insert          v1
Understanding Eventual Consistency
     Thread #1   Primary   Secondary

      Insert         v1




                            v1
Understanding Eventual Consistency
      Thread #1   Primary   Secondary

      Insert          v1




       Read
                             v1
Understanding Eventual Consistency
           Thread #1   Primary   Secondary

           Insert           v1




reads v1   Read
                                  v1
Understanding Eventual Consistency
            Thread #1   Primary   Secondary

            Insert           v1




reads v1    Read
                                    v1



           Update            v2
Understanding Eventual Consistency
            Thread #1   Primary   Secondary

            Insert           v1




reads v1    Read
                                   v1



           Update            v2




                                   v2
Understanding Eventual Consistency
           Thread #1   Primary   Secondary

            Insert          v1




reads v1    Read
                                  v1



           Update           v2




            Read                  v2
Understanding Eventual Consistency
           Thread #1   Primary   Secondary

            Insert         v1




reads v1    Read
                                  v1



           Update          v2




reads v2    Read                  v2
Understanding Eventual Consistency
    Thread #1   Primary        Secondary   Thread #2

      Insert              v1




       Read
                                 v1



     Update               v2




       Read                      v2
Understanding Eventual Consistency
    Thread #1   Primary        Secondary   Thread #2

      Insert              v1




       Read
                                 v1



     Update               v2




       Read                      v2
Understanding Eventual Consistency
    Thread #1   Primary        Secondary   Thread #2

      Insert              v1
                                                       v1 does not
                                                         exist on
       Read                                            Secondary
                                 v1



     Update               v2




       Read                      v2
Understanding Eventual Consistency
    Thread #1   Primary        Secondary   Thread #2

      Insert              v1
                                                       v1 does not
                                                         exist on
       Read                                            Secondary
                                 v1



     Update               v2

                                                   Reads v1 but
                                                   Primary at v2
       Read                      v2


                                                        Read v2
Example 7 - Eventual Consistency
http://community.qlikview.com/cfs-filesystemfile.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/theqlikviewblog/Cutting-Grass-with-Scissors-_2D00_-2.jpg
http://www.bitquill.net/blog/wp-content/uploads/2008/07/pack_of_harvesters.jpg
MongoDB Sharding
• Automatic partitioning and management

• Range based

• Convert to sharded system with no downtime

• Fully consistent
How mongoDB Sharding works
> db.runCommand({addshard: "shard1"});
> db.runCommand({shardCollection: "mydb.users",
                 key: {age: 1}})

               -∞   +∞  




• Range keys from -∞ to +∞
• Ranges are stored as "chunks"
How mongoDB Sharding works
> db.users.save({age: 40})



               -∞   +∞  

       -∞   40      41 +∞  



• Data in inserted
• Ranges are split into more "chunks"
How mongoDB Sharding works
> db.users.save({age: 40})
> db.users.save({age: 50})
> db.users.save({age: 60})

                 -∞   +∞  

            -∞   40     41 +∞  

                   41 50       51 +∞  
                             51 60   61 +∞  
How mongoDB Sharding works

> db.runCommand({addshard: "shard2"});
> db.runCommand({addshard: "shard3"});




    -∞   40
    41 50
    51 60
    61 +∞  
How mongoDB Sharding works

> db.runCommand({addshard: "shard2"});
> db.runCommand({addshard: "shard3"});




 shard1
    -∞   40
    41 50
    51 60
    61 +∞  
How mongoDB Sharding works

> db.runCommand({addshard: "shard2"});
> db.runCommand({addshard: "shard3"});




 shard1                shard2            shard3
    -∞   40
                          41 50
                                          51 60
                         61 +∞  
Architecture
                               app       app


    Config Servers
                               mongos    mongos
      C1

      C2

      C3
                                                   Replica Set
                     mongod    mongod    mongod    mongod

                     mongod    mongod    mongod    mongod

                     mongod    mongod    mongod    mongod

                     Shard 1   Shard 2   Shard 3    Shard 4
Balancing
                                                  mongos                         config
                                                 mongos
                                                  balancer
                                                                                 config

                                                                                 config
                                      Data inserted
                Imbalance             all in a range


  1   2    3     4

  5   6    7     8

  9   10   11    12         13   14    15   16               17   18   19   20   21   22   23   24




      Shard 1                    Shard 2                          Shard 3             Shard 4
Balancing
                                      mongos                         config
                                     mongos
                                      balancer
                                                                     config

                                                                     config
                               Move chunk 1
                               to Shard 2


  1   2    3    4

  5   6    7    8

  9   10   11   12   13   14    15   16          17   18   19   20   21   22   23   24




      Shard 1             Shard 2                     Shard 3             Shard 4
Balancing
                                         mongos                         config
                                         balancer
                                                                        config

                                                                        config




  1   2    3    4

  5   6    7    8

  9   10   11   12   13   14   15   16              17   18   19   20   21   22   23   24




      Shard 1             Shard 2                        Shard 3             Shard 4
Balancing
                                         mongos                         config
                                         balancer
                                                                        config

                                                                        config




      2    3    4

  5   6    7    8    1

  9   10   11   12   13   14   15   16              17   18   19   20   21   22   23   24




      Shard 1             Shard 2                        Shard 3             Shard 4
Balancing
                                     mongos                         config
                                    mongos
                                     balancer
                                                                    config

                                                                    config




      2    3    4

  5   6    7    8    1

  9   10   11   12   13   14   15   16          17   18   19   20   21   22   23   24




      Shard 1             Shard 2                    Shard 3             Shard 4
Example 8 - Sharding
Questions
• MongoDB 2.2
 – Improved concurrency
 – Tag-aware sharding
 – Aggregation framework
 – TTL collections


• Free online MongoDB training
 – Develop
 – Deploy
 – Classes start Oct. 2012

More Related Content

Viewers also liked (11)

PDF
AngularJS performance & production tips
Nir Kaufman
 
PPTX
jDays - Spring Boot under the Hood
Nicolas Fränkel
 
PDF
Hadoop, the Apple of Our Eyes (這些年,我們一起追的 Hadoop)
Kuo-Chun Su
 
PDF
Microservice With Spring Boot and Spring Cloud
Eberhard Wolff
 
PPTX
Morphia, Spring Data & Co.
Tobias Trelle
 
PDF
Java Persistence Frameworks for MongoDB
MongoDB
 
PDF
ng-owasp: OWASP Top 10 for AngularJS Applications
Kevin Hakanson
 
PPTX
Spring boot
sdeeg
 
PPTX
Leaky Bucket & Tocken Bucket - Traffic shaping
Vimal Dewangan
 
PDF
The Art of AngularJS in 2015
Matt Raible
 
AngularJS performance & production tips
Nir Kaufman
 
jDays - Spring Boot under the Hood
Nicolas Fränkel
 
Hadoop, the Apple of Our Eyes (這些年,我們一起追的 Hadoop)
Kuo-Chun Su
 
Microservice With Spring Boot and Spring Cloud
Eberhard Wolff
 
Morphia, Spring Data & Co.
Tobias Trelle
 
Java Persistence Frameworks for MongoDB
MongoDB
 
ng-owasp: OWASP Top 10 for AngularJS Applications
Kevin Hakanson
 
Spring boot
sdeeg
 
Leaky Bucket & Tocken Bucket - Traffic shaping
Vimal Dewangan
 
The Art of AngularJS in 2015
Matt Raible
 

Similar to The Spring Data MongoDB Project (20)

PDF
Thoughts on Transaction and Consistency Models
iammutex
 
PDF
Consistency Models in New Generation Databases
iammutex
 
PDF
Consistency-New-Generation-Databases
Roger Xia
 
PPTX
Pnuts
smilekg1220
 
PPTX
Presentation
kiarash1361
 
POTX
Presentation
kiarash1361
 
PDF
NoSQL - how it works (@pavlobaron)
Pavlo Baron
 
PPT
MongoDB Basic Concepts
MongoDB
 
PDF
Automated conflict resolution - enabling masterless data distribution (Rune S...
Swiss Big Data User Group
 
PDF
Why we cannot ignore Functional Programming
Mario Fusco
 
PDF
Coherence Implementation Patterns - Sig Nov 2011
Ben Stopford
 
PDF
Updateable Fields in Lucene and other Codec Applications
lucenerevolution
 
PPTX
Cистема распределенного, масштабируемого и высоконадежного хранения данных дл...
Ontico
 
PDF
Distributed computing the Google way
Eduard Hildebrandt
 
PDF
Persistent Data Structures by @aradzie
Vasil Remeniuk
 
PDF
Challenges in Maintaining a High Performance Search Engine Written in Java
lucenerevolution
 
PDF
Design Patterns For Distributed NO-reational databases
lovingprince58
 
PDF
How MongoDB works
Vladimir Miguro
 
PDF
Thoughts on consistency models
rogerbodamer
 
PDF
Rc173 010d-json 2
Yongfa Huang
 
Thoughts on Transaction and Consistency Models
iammutex
 
Consistency Models in New Generation Databases
iammutex
 
Consistency-New-Generation-Databases
Roger Xia
 
Presentation
kiarash1361
 
Presentation
kiarash1361
 
NoSQL - how it works (@pavlobaron)
Pavlo Baron
 
MongoDB Basic Concepts
MongoDB
 
Automated conflict resolution - enabling masterless data distribution (Rune S...
Swiss Big Data User Group
 
Why we cannot ignore Functional Programming
Mario Fusco
 
Coherence Implementation Patterns - Sig Nov 2011
Ben Stopford
 
Updateable Fields in Lucene and other Codec Applications
lucenerevolution
 
Cистема распределенного, масштабируемого и высоконадежного хранения данных дл...
Ontico
 
Distributed computing the Google way
Eduard Hildebrandt
 
Persistent Data Structures by @aradzie
Vasil Remeniuk
 
Challenges in Maintaining a High Performance Search Engine Written in Java
lucenerevolution
 
Design Patterns For Distributed NO-reational databases
lovingprince58
 
How MongoDB works
Vladimir Miguro
 
Thoughts on consistency models
rogerbodamer
 
Rc173 010d-json 2
Yongfa Huang
 
Ad

More from MongoDB (20)

PDF
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
PDF
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
PDF
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB
 
PDF
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB
 
PDF
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB
 
PDF
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB
 
PDF
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
PDF
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB
 
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB
 
PDF
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB
 
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB
 
PDF
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB
 
PDF
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB
 
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB
 
Ad

Recently uploaded (20)

PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
July Patch Tuesday
Ivanti
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
July Patch Tuesday
Ivanti
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 

The Spring Data MongoDB Project

Editor's Notes