SlideShare a Scribd company logo
1 of 17
MongoDB Live Coding Session
tobias.trelle@codecentric.de
@tobiastrelle
 codecentric AG
„It‘s not my fault the chapters are short,
  MongoDB is just easy to learn“

      from „The Little MongoDB book“




codecentric AG
MongoDB User Groups by codecentric



                  MongoDB User-Gruppe Düsseldorf
                 https://www.xing.com/net/mongodb-dus
                               @MongoDUS
                         Contact: Tobias Trelle




                 MongoDB User-Gruppe Frankfurt/Main
                  https://www.xing.com/net/mongodb-ffm
                          Contact: Uwe Seiler



codecentric AG
What is MongoDB?

      Named from „humongous“ = gigantic   http://www.mongodb.org


      NoSQL datastore, Open Source https://github.com/mongodb
      support from manufacturer 10gen http://www.10gen.com


      Highly scalable (scale-out)

      Stores so called „documents“


      Supports replication & sharding


      Map/Reduce


      Geospatial indexes / queries

codecentric AG
Basic structure of a MongoDB server


                           Server



                          Database
Relational counterpart                 But …
                                       Flexible
            Table         Collection
                                       Schema

                 Row      Document


                                        - Arrays
                 Column     Field
                                        - recursive
codecentric AG
What‘s a document?

      Single record that can be stored in a collection


      JSON = JavaScript Object Notation (internal representation BSON = Binary JSON)


      var doc =      {
                     title: „MongoDB_Live_Hacking.pptx“,
                     tags: [ „cc“, „mongodb“, „nosql“ ],
                     slides: [
                               { nr = 1, header = „MongoDB User Groups by codecentric“},
                               { nr = 2, header = „MongoDB at codedcentric WiKi“},
                               …
                               ]
                     };




codecentric AG
Live Session

      CRUD operations


      Queries


      Geospatial Queries


      Map/Reduce


      Replication


      Sharding


      Raw Java API & Spring Data API


codecentric AG
Geospatial Queries

      Queries based on
      2-dimensional coordinates


      _id: "A", position: [0.001, -0.002]
      _id: "B", position: [0.75, 0.75]
      _id: "C", position: [0.5, 0.5]
      _id: "D", position: [-0.5, -0.5]


      Queries based on distances
      & shapes


      Details:
      http://blog.codecentric.de/en/2012/02/spring-data-mongodb-geospatial-queries/




codecentric AG
Map/Reduce

      Data processing algorithm based on two phases: map & reduce


      Code execution co-located with the data


      Map phase can be run in parallel (on multiple nodes etc.) on huge data sets


      MongoDB map / reduce:

                 runs on a subset of / all documents of a collection


                 Map / Reduce algorithms are JS functions


                 Output documents of the map function are input to the reduce function


                 Results are documents stored in a target collection
codecentric AG
Map/Reduce example
      We want to count occurences of tags assigned to our documents:
          {name: „Doc 1“, tags: [ „cc“, „mongodb“, „nosql“ ] }
          {name: „Doc 2“, tags: [ „cc“, „agile“ ] }              Map output:
          {name: „Doc 3“, tags: [ „cc“ ] }                       key = „cc“, value = {count: 1}
                                                                              key = „mongodb“, value = {count: 1}
                                                                              key = „nosql“, value = {count: 1}
      Map function:
                                                                              key = „cc“, value = {count: 1}
      function() { this.tags.forEach( function(tag) {                         key = „agile“, value = {count: 1}
                       emit( tag, {count: 1} )                                key = „cc“, value = {count: 1}
                       })
      }
      Reduce function:                                  Reduce input:
      function(key, values) {                           key = „cc“, values = [ {count: 1}, {count: 1}, {count: 1} ]
             var result = {count: 0};
                                                        key = „mongodb“, values = [ {count: 1} ]
             values.forEach(function(value) {
                                                        key = „nosql“, values = [ {count: 1} ]
                       result.count += value.count;
                                                        key = „agile“, values = [ {count: 1} ]
             });
             return result;
      }
codecentric AG
MongoDB Replication

      A cluster is called „replica set“
      Uses Master/Slave replication
      Writes from clients go to the master only
      If the master goes down, the slaves elect a new master (n > 2)

                                                    Replica set w/ n = 3



                                                                           Slave 1

                 Client                    Master

                                                                           Slave 2



codecentric AG
MongoDB Sharding

      Data is distributed over n nodes, each record is persisted only once
      Data only on the shard nodes
      Config Server = book keeper, knows where the data is
      Switch: Gateway for clients

                                                  Sharding setup

                                Config
                                Server                                 Shard 1




                                                                        Shard 2
             Client             Switch


codecentric AG
MongoDB Sharding in Production

      Each shard is a replica set + 3 config servers




Source: http://www.mongodb.org/display/DOCS/Sharding+Introduction
codecentric AG
MongoDB Sharding Example: Initial State
mongos> sh.status()
--- Sharding Status ---
   sharding version: { "_id" : 1, "version" : 3 }
   shards:                                                                    2 Shards
             {   "_id" : "shard0000",     "host" : "tmp-pc:9000" }
             {   "_id" : "shard0001",     "host" : "tmp-pc:9001" }
   databases:
             {   "_id" : "admin",   "partitioned" : false,    "primary" : "config" }
             {   "_id" : "data",    "partitioned" : true,    "primary" : "shard0000" }
                      data.foo chunks:
                                         shard0000      1
                              { "age" : { $minKey : 1 } } -->> { "age" : { $maxKey : 1 } } on : shard0000 { "t" : 1000,
     "i" : 0 }




codecentric AG
MongoDB Sharding Example: Multiple Chunks
mongos> sh.status()
--- Sharding Status ---
   sharding version: { "_id" : 1, "version" : 3 }
   shards:                                                                    2 Shards
             {   "_id" : "shard0000",     "host" : "tmp-pc:9000" }
             {   "_id" : "shard0001",     "host" : "tmp-pc:9001" }
   databases:
             {   "_id" : "admin",   "partitioned" : false,    "primary" : "config" }
             {   "_id" : "data",    "partitioned" : true,    "primary" : "shard0000" }
                      data.foo chunks:
                                         shard0001      4
                                         shard0000      5
              Chunks
                              { "age" : { $minKey : 1 } } -->> { "age" : 50 } on : shard0001 { "t" : 2000, "i" : 0 }
            are equally
            distributed       { "age" : 50 } -->> { "age" : 53 } on : shard0001 { "t" : 3000, "i" : 0 }
                              { "age" : 53 } -->> { "age" : 54 } on : shard0001 { "t" : 4000, "i" : 0 }
                              { "age" : 54 } -->> { "age" : 58 } on : shard0001 { "t" : 5000, "i" : 0 }
                              { "age" : 58 } -->> { "age" : 60 } on : shard0000 { "t" : 5000, "i" : 1 }
                              { "age" : 60 } -->> { "age" : 63 } on : shard0000 { "t" : 1000, "i" : 14 }
                              { "age" : 63 } -->> { "age" : 65 } on : shard0000 { "t" : 1000, "i" : 11 }
                              { "age" : 65 } -->> { "age" : 69 } on : shard0000 { "t" : 1000, "i" : 12 }
                              { "age" : 69 } -->> { "age" : { $maxKey : 1 } } on : shard0000 { "t" : 1000, "i" : 4 }


codecentric AG
MongoDB API
      Drivers for many languages (Java, Ruby, PHP, C++, …)
      Low level Java API: MongoDB Java Driver
      Spring Data MongoDB: Repository Support + Objekt/Collection Mapping

                                                 Spring Data
                                       CrudRepository     PagingAndSortingRepository

                       Spring Data      Spring Data          Spring Data           Spring Data
                           JPA           MongoDB               Neo4j                    …
                      JpaRepository   MongoRepository      GraphRepository
                                      MongoTemplate         Neo4jTemplate


                                                           Embedded     REST


                           JPA        Mongo Java Driver

                          JDBC



                         RDBMS             MongoDB              Neo4j                   …




codecentric AG
QUESTION?

Tobias Trelle

codecentric AG
Merscheider Str. 1
42699 Solingen

tel              +49 (0) 212.233628.47
fax              +49 (0) 212.233628.79
mail             Tobias.Trelle@codecentric.de
twitter          @tobiastrelle

www.codecentric.de
www.mbg-online.de
blog.codecentric.de
www.xing.com/net/mongodb-dus


codecentric AG                                  20.08.2012   17

More Related Content

What's hot

Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
MongoDB
 
Java Development with MongoDB
Java Development with MongoDBJava Development with MongoDB
Java Development with MongoDB
Scott Hernandez
 

What's hot (20)

Introduction to Restkit
Introduction to RestkitIntroduction to Restkit
Introduction to Restkit
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 
Morphia, Spring Data & Co.
Morphia, Spring Data & Co.Morphia, Spring Data & Co.
Morphia, Spring Data & Co.
 
Embracing the-power-of-refactor
Embracing the-power-of-refactorEmbracing the-power-of-refactor
Embracing the-power-of-refactor
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJS
 
MongoDB .local Munich 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...
MongoDB .local Munich 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...MongoDB .local Munich 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...
MongoDB .local Munich 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...
 
Java development with MongoDB
Java development with MongoDBJava development with MongoDB
Java development with MongoDB
 
MongoDB .local Munich 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local Munich 2019: Best Practices for Working with IoT and Time-seri...MongoDB .local Munich 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local Munich 2019: Best Practices for Working with IoT and Time-seri...
 
Java Development with MongoDB
Java Development with MongoDBJava Development with MongoDB
Java Development with MongoDB
 
Cnam azure 2014 mobile services
Cnam azure 2014   mobile servicesCnam azure 2014   mobile services
Cnam azure 2014 mobile services
 
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
 
Inside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source Database
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
 
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDBMongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
 
Hazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMSHazelcast and MongoDB at Cloud CMS
Hazelcast and MongoDB at Cloud CMS
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 
High Performance XQuery Processing in PHP with Zorba by Vikram Vaswani
High Performance XQuery Processing in PHP with Zorba by Vikram VaswaniHigh Performance XQuery Processing in PHP with Zorba by Vikram Vaswani
High Performance XQuery Processing in PHP with Zorba by Vikram Vaswani
 
Orion Context Broker NGSI-v2 Overview for Developers That Already Know Ngsi-v...
Orion Context Broker NGSI-v2 Overview for Developers That Already Know Ngsi-v...Orion Context Broker NGSI-v2 Overview for Developers That Already Know Ngsi-v...
Orion Context Broker NGSI-v2 Overview for Developers That Already Know Ngsi-v...
 
What is the ServiceStack?
What is the ServiceStack?What is the ServiceStack?
What is the ServiceStack?
 
Return of c++
Return of c++Return of c++
Return of c++
 

Viewers also liked

Ppt newton's law
Ppt newton's lawPpt newton's law
Ppt newton's law
mamardc
 
Theanatomyofanentrepreneur 100105180411-phpapp01
Theanatomyofanentrepreneur 100105180411-phpapp01Theanatomyofanentrepreneur 100105180411-phpapp01
Theanatomyofanentrepreneur 100105180411-phpapp01
Deepak R Gorad
 
Power electronics projects
Power electronics projectsPower electronics projects
Power electronics projects
Senthil Kumar
 
Xamarin Mobile March 2014
Xamarin Mobile March 2014Xamarin Mobile March 2014
Xamarin Mobile March 2014
Joe Koletar
 
deepak gorad Final csr
deepak gorad Final csrdeepak gorad Final csr
deepak gorad Final csr
Deepak R Gorad
 
2 power and hydrogen generation figures
2 power and hydrogen generation figures2 power and hydrogen generation figures
2 power and hydrogen generation figures
novi5036
 

Viewers also liked (20)

Leigh lillis medical TW resume 8 2016
Leigh lillis medical TW resume 8 2016Leigh lillis medical TW resume 8 2016
Leigh lillis medical TW resume 8 2016
 
Meatco AGM 2012 - CEO Presentation
Meatco AGM 2012 - CEO PresentationMeatco AGM 2012 - CEO Presentation
Meatco AGM 2012 - CEO Presentation
 
Windows7
Windows7Windows7
Windows7
 
Ppt newton's law
Ppt newton's lawPpt newton's law
Ppt newton's law
 
2012 Ford Fiesta Brochure | Mason City Ford, Waverly Ford, and Clear Lake Ford
2012 Ford Fiesta Brochure | Mason City Ford, Waverly Ford, and Clear Lake Ford2012 Ford Fiesta Brochure | Mason City Ford, Waverly Ford, and Clear Lake Ford
2012 Ford Fiesta Brochure | Mason City Ford, Waverly Ford, and Clear Lake Ford
 
Wireless projects
Wireless projectsWireless projects
Wireless projects
 
what is Blubbr? and how to use it?
what is Blubbr? and how to use it?what is Blubbr? and how to use it?
what is Blubbr? and how to use it?
 
Theanatomyofanentrepreneur 100105180411-phpapp01
Theanatomyofanentrepreneur 100105180411-phpapp01Theanatomyofanentrepreneur 100105180411-phpapp01
Theanatomyofanentrepreneur 100105180411-phpapp01
 
Enhance WordPress Search Using Sphinx
Enhance WordPress Search Using SphinxEnhance WordPress Search Using Sphinx
Enhance WordPress Search Using Sphinx
 
Tcdnug xamarin
Tcdnug xamarinTcdnug xamarin
Tcdnug xamarin
 
The Social Challenge of 1.5°C Webinar: Karen O'Brien
The Social Challenge of 1.5°C Webinar: Karen O'BrienThe Social Challenge of 1.5°C Webinar: Karen O'Brien
The Social Challenge of 1.5°C Webinar: Karen O'Brien
 
Power electronics projects
Power electronics projectsPower electronics projects
Power electronics projects
 
Mechanical projects
Mechanical projectsMechanical projects
Mechanical projects
 
Xamarin Mobile March 2014
Xamarin Mobile March 2014Xamarin Mobile March 2014
Xamarin Mobile March 2014
 
Hari kantin sekolah
Hari kantin sekolahHari kantin sekolah
Hari kantin sekolah
 
Port folio 20121005
Port folio 20121005Port folio 20121005
Port folio 20121005
 
deepak gorad Final csr
deepak gorad Final csrdeepak gorad Final csr
deepak gorad Final csr
 
2012 Media Highlights
2012 Media Highlights2012 Media Highlights
2012 Media Highlights
 
2 power and hydrogen generation figures
2 power and hydrogen generation figures2 power and hydrogen generation figures
2 power and hydrogen generation figures
 
Leigh lillis resume 7 2016
Leigh lillis resume 7 2016Leigh lillis resume 7 2016
Leigh lillis resume 7 2016
 

Similar to MongoDB Live Hacking

MongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: ShardingMongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: Sharding
MongoDB
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
MongoDB
 
MongoDB: Intro & Application for Big Data
MongoDB: Intro & Application  for Big DataMongoDB: Intro & Application  for Big Data
MongoDB: Intro & Application for Big Data
Takahiro Inoue
 

Similar to MongoDB Live Hacking (20)

Building a Scalable Distributed Stats Infrastructure with Storm and KairosDB
Building a Scalable Distributed Stats Infrastructure with Storm and KairosDBBuilding a Scalable Distributed Stats Infrastructure with Storm and KairosDB
Building a Scalable Distributed Stats Infrastructure with Storm and KairosDB
 
MongoDB, Hadoop and humongous data - MongoSV 2012
MongoDB, Hadoop and humongous data - MongoSV 2012MongoDB, Hadoop and humongous data - MongoSV 2012
MongoDB, Hadoop and humongous data - MongoSV 2012
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and Python
 
MongoDB Days Silicon Valley: MongoDB and the Hadoop Connector
MongoDB Days Silicon Valley: MongoDB and the Hadoop ConnectorMongoDB Days Silicon Valley: MongoDB and the Hadoop Connector
MongoDB Days Silicon Valley: MongoDB and the Hadoop Connector
 
Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo db
 
MongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: ShardingMongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: Sharding
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 
MongoDB: Intro & Application for Big Data
MongoDB: Intro & Application  for Big DataMongoDB: Intro & Application  for Big Data
MongoDB: Intro & Application for Big Data
 
NoSQL Infrastructure
NoSQL InfrastructureNoSQL Infrastructure
NoSQL Infrastructure
 
Advanced Replication
Advanced ReplicationAdvanced Replication
Advanced Replication
 
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & AggregationWebinar: Applikationsentwicklung mit MongoDB: Teil 5: Reporting & Aggregation
Webinar: Applikationsentwicklung mit MongoDB : Teil 5: Reporting & Aggregation
 
Mongodb workshop
Mongodb workshopMongodb workshop
Mongodb workshop
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & Analytics
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
It's 10pm: Do You Know Where Your Writes Are?
It's 10pm: Do You Know Where Your Writes Are?It's 10pm: Do You Know Where Your Writes Are?
It's 10pm: Do You Know Where Your Writes Are?
 
SQL? NoSQL? NewSQL?!? What's a Java developer to do? - PhillyETE 2012
SQL? NoSQL? NewSQL?!? What's a Java developer to do? - PhillyETE 2012SQL? NoSQL? NewSQL?!? What's a Java developer to do? - PhillyETE 2012
SQL? NoSQL? NewSQL?!? What's a Java developer to do? - PhillyETE 2012
 
Unlocking Your Hadoop Data with Apache Spark and CDH5
Unlocking Your Hadoop Data with Apache Spark and CDH5Unlocking Your Hadoop Data with Apache Spark and CDH5
Unlocking Your Hadoop Data with Apache Spark and CDH5
 
Maintenance for MongoDB Replica Sets
Maintenance for MongoDB Replica SetsMaintenance for MongoDB Replica Sets
Maintenance for MongoDB Replica Sets
 
CouchDB on Rails
CouchDB on RailsCouchDB on Rails
CouchDB on Rails
 

More from Tobias Trelle

MongoDB - Riesige Datenmengen schemafrei verwalten
MongoDB - Riesige Datenmengen schemafrei verwaltenMongoDB - Riesige Datenmengen schemafrei verwalten
MongoDB - Riesige Datenmengen schemafrei verwalten
Tobias Trelle
 
Morphia, Spring Data & Co
Morphia, Spring Data & CoMorphia, Spring Data & Co
Morphia, Spring Data & Co
Tobias Trelle
 

More from Tobias Trelle (11)

TDD mit JUnit und Mockito
TDD mit JUnit und MockitoTDD mit JUnit und Mockito
TDD mit JUnit und Mockito
 
NoSQL - Einführung in Graphen-Datenbanken mit Neo4j
NoSQL - Einführung in Graphen-Datenbanken mit Neo4jNoSQL - Einführung in Graphen-Datenbanken mit Neo4j
NoSQL - Einführung in Graphen-Datenbanken mit Neo4j
 
Einführung in NoSQL-Datenbanken
Einführung in NoSQL-DatenbankenEinführung in NoSQL-Datenbanken
Einführung in NoSQL-Datenbanken
 
MongoDB Einführung
MongoDB EinführungMongoDB Einführung
MongoDB Einführung
 
MongoDB - Riesige Datenmengen schemafrei verwalten
MongoDB - Riesige Datenmengen schemafrei verwaltenMongoDB - Riesige Datenmengen schemafrei verwalten
MongoDB - Riesige Datenmengen schemafrei verwalten
 
Test Automation for NoSQL Databases
Test Automation for NoSQL DatabasesTest Automation for NoSQL Databases
Test Automation for NoSQL Databases
 
Morphia, Spring Data & Co
Morphia, Spring Data & CoMorphia, Spring Data & Co
Morphia, Spring Data & Co
 
Spring Data, Jongo & Co.
Spring Data, Jongo & Co.Spring Data, Jongo & Co.
Spring Data, Jongo & Co.
 
An introduction to MongoDB and Ruby
An introduction to MongoDB and RubyAn introduction to MongoDB and Ruby
An introduction to MongoDB and Ruby
 
OOP 2013: Praktische Einführung in MongoDB
OOP 2013: Praktische Einführung in MongoDBOOP 2013: Praktische Einführung in MongoDB
OOP 2013: Praktische Einführung in MongoDB
 
MongoDB Munich 2012: Spring Data MongoDB
MongoDB Munich 2012: Spring Data MongoDBMongoDB Munich 2012: Spring Data MongoDB
MongoDB Munich 2012: Spring Data MongoDB
 

Recently uploaded

Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
FIDO Alliance
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 

Recently uploaded (20)

WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 

MongoDB Live Hacking

  • 1. MongoDB Live Coding Session tobias.trelle@codecentric.de @tobiastrelle codecentric AG
  • 2. „It‘s not my fault the chapters are short, MongoDB is just easy to learn“ from „The Little MongoDB book“ codecentric AG
  • 3. MongoDB User Groups by codecentric MongoDB User-Gruppe Düsseldorf https://www.xing.com/net/mongodb-dus @MongoDUS Contact: Tobias Trelle MongoDB User-Gruppe Frankfurt/Main https://www.xing.com/net/mongodb-ffm Contact: Uwe Seiler codecentric AG
  • 4. What is MongoDB? Named from „humongous“ = gigantic http://www.mongodb.org NoSQL datastore, Open Source https://github.com/mongodb support from manufacturer 10gen http://www.10gen.com Highly scalable (scale-out) Stores so called „documents“ Supports replication & sharding Map/Reduce Geospatial indexes / queries codecentric AG
  • 5. Basic structure of a MongoDB server Server Database Relational counterpart But … Flexible Table Collection Schema Row Document - Arrays Column Field - recursive codecentric AG
  • 6. What‘s a document? Single record that can be stored in a collection JSON = JavaScript Object Notation (internal representation BSON = Binary JSON) var doc = { title: „MongoDB_Live_Hacking.pptx“, tags: [ „cc“, „mongodb“, „nosql“ ], slides: [ { nr = 1, header = „MongoDB User Groups by codecentric“}, { nr = 2, header = „MongoDB at codedcentric WiKi“}, … ] }; codecentric AG
  • 7. Live Session CRUD operations Queries Geospatial Queries Map/Reduce Replication Sharding Raw Java API & Spring Data API codecentric AG
  • 8. Geospatial Queries Queries based on 2-dimensional coordinates _id: "A", position: [0.001, -0.002] _id: "B", position: [0.75, 0.75] _id: "C", position: [0.5, 0.5] _id: "D", position: [-0.5, -0.5] Queries based on distances & shapes Details: http://blog.codecentric.de/en/2012/02/spring-data-mongodb-geospatial-queries/ codecentric AG
  • 9. Map/Reduce Data processing algorithm based on two phases: map & reduce Code execution co-located with the data Map phase can be run in parallel (on multiple nodes etc.) on huge data sets MongoDB map / reduce: runs on a subset of / all documents of a collection Map / Reduce algorithms are JS functions Output documents of the map function are input to the reduce function Results are documents stored in a target collection codecentric AG
  • 10. Map/Reduce example We want to count occurences of tags assigned to our documents: {name: „Doc 1“, tags: [ „cc“, „mongodb“, „nosql“ ] } {name: „Doc 2“, tags: [ „cc“, „agile“ ] } Map output: {name: „Doc 3“, tags: [ „cc“ ] } key = „cc“, value = {count: 1} key = „mongodb“, value = {count: 1} key = „nosql“, value = {count: 1} Map function: key = „cc“, value = {count: 1} function() { this.tags.forEach( function(tag) { key = „agile“, value = {count: 1} emit( tag, {count: 1} ) key = „cc“, value = {count: 1} }) } Reduce function: Reduce input: function(key, values) { key = „cc“, values = [ {count: 1}, {count: 1}, {count: 1} ] var result = {count: 0}; key = „mongodb“, values = [ {count: 1} ] values.forEach(function(value) { key = „nosql“, values = [ {count: 1} ] result.count += value.count; key = „agile“, values = [ {count: 1} ] }); return result; } codecentric AG
  • 11. MongoDB Replication A cluster is called „replica set“ Uses Master/Slave replication Writes from clients go to the master only If the master goes down, the slaves elect a new master (n > 2) Replica set w/ n = 3 Slave 1 Client Master Slave 2 codecentric AG
  • 12. MongoDB Sharding Data is distributed over n nodes, each record is persisted only once Data only on the shard nodes Config Server = book keeper, knows where the data is Switch: Gateway for clients Sharding setup Config Server Shard 1 Shard 2 Client Switch codecentric AG
  • 13. MongoDB Sharding in Production Each shard is a replica set + 3 config servers Source: http://www.mongodb.org/display/DOCS/Sharding+Introduction codecentric AG
  • 14. MongoDB Sharding Example: Initial State mongos> sh.status() --- Sharding Status --- sharding version: { "_id" : 1, "version" : 3 } shards: 2 Shards { "_id" : "shard0000", "host" : "tmp-pc:9000" } { "_id" : "shard0001", "host" : "tmp-pc:9001" } databases: { "_id" : "admin", "partitioned" : false, "primary" : "config" } { "_id" : "data", "partitioned" : true, "primary" : "shard0000" } data.foo chunks: shard0000 1 { "age" : { $minKey : 1 } } -->> { "age" : { $maxKey : 1 } } on : shard0000 { "t" : 1000, "i" : 0 } codecentric AG
  • 15. MongoDB Sharding Example: Multiple Chunks mongos> sh.status() --- Sharding Status --- sharding version: { "_id" : 1, "version" : 3 } shards: 2 Shards { "_id" : "shard0000", "host" : "tmp-pc:9000" } { "_id" : "shard0001", "host" : "tmp-pc:9001" } databases: { "_id" : "admin", "partitioned" : false, "primary" : "config" } { "_id" : "data", "partitioned" : true, "primary" : "shard0000" } data.foo chunks: shard0001 4 shard0000 5 Chunks { "age" : { $minKey : 1 } } -->> { "age" : 50 } on : shard0001 { "t" : 2000, "i" : 0 } are equally distributed { "age" : 50 } -->> { "age" : 53 } on : shard0001 { "t" : 3000, "i" : 0 } { "age" : 53 } -->> { "age" : 54 } on : shard0001 { "t" : 4000, "i" : 0 } { "age" : 54 } -->> { "age" : 58 } on : shard0001 { "t" : 5000, "i" : 0 } { "age" : 58 } -->> { "age" : 60 } on : shard0000 { "t" : 5000, "i" : 1 } { "age" : 60 } -->> { "age" : 63 } on : shard0000 { "t" : 1000, "i" : 14 } { "age" : 63 } -->> { "age" : 65 } on : shard0000 { "t" : 1000, "i" : 11 } { "age" : 65 } -->> { "age" : 69 } on : shard0000 { "t" : 1000, "i" : 12 } { "age" : 69 } -->> { "age" : { $maxKey : 1 } } on : shard0000 { "t" : 1000, "i" : 4 } codecentric AG
  • 16. MongoDB API Drivers for many languages (Java, Ruby, PHP, C++, …) Low level Java API: MongoDB Java Driver Spring Data MongoDB: Repository Support + Objekt/Collection Mapping Spring Data CrudRepository PagingAndSortingRepository Spring Data Spring Data Spring Data Spring Data JPA MongoDB Neo4j … JpaRepository MongoRepository GraphRepository MongoTemplate Neo4jTemplate Embedded REST JPA Mongo Java Driver JDBC RDBMS MongoDB Neo4j … codecentric AG
  • 17. QUESTION? Tobias Trelle codecentric AG Merscheider Str. 1 42699 Solingen tel +49 (0) 212.233628.47 fax +49 (0) 212.233628.79 mail Tobias.Trelle@codecentric.de twitter @tobiastrelle www.codecentric.de www.mbg-online.de blog.codecentric.de www.xing.com/net/mongodb-dus codecentric AG 20.08.2012 17