SlideShare une entreprise Scribd logo
1  sur  52
MongoDB (for Java Developers)
Anthony Slabinck
Who am I?
• Internship at Provikmo
• 3 years 6 months
• Competitive cyclist
What is MongoDB?
• The leading NoSQL database (http://db-engines.com/en/)
• Open source
• Non-relational JSON document store
• BSON (Binary JSON)
• Dynamic schema
• Agile
• Scalable through replicaton and sharding
3
The leading NoSQL database
4
• LinkedIn Job Skills
• Google Search
• Indeed.com Trends
MongoDB relative to relational databases
5
Who uses MongoDB?
6
By use case
• Single View
• Internet of Things
• Mobile
• Real-Time Analytics
• Personalization
• Content Management
• Catalog
7
From relational databases to MongoDB
8
{
first_name: "Anthony",
surname: "Slabinck",
city: "Bruges",
location: [45.123,47.232],
cars: [
{ model: "Bentley",
year: 1973,
value: 100000 },
{ mode: "Rolls Royce",
year: 1965,
value: 330000 } ]
}
MongoDB is full featured
9
MongoDB CRUD Operations
10
Documents
MongoDB CRUD Operations
11
Collections
MongoDB CRUD Operations
12
Read operations
MongoDB CRUD Operations
13
Read operations
MongoDB CRUD Operations
14
Write operations - insert
MongoDB CRUD Operations
15
Write operations - update
MongoDB CRUD Operations
16
Write operations - remove
Installation
• Download MongoDB from http://www.mongodb.org/downloads
• Download the Java Driver (maven)
• mongod
• Daemon process
• mongo
• Interactive JavaScript shell interface
• Robomongo
• Cross-platform management tool
17
Getting started with MongoDB
18
Demo
Data Models
• Flexible schema
• Collections do not enforce document structure
• Consider how applications will use your database
• No foreign keys, no joins
• Relationships between data
• Embedded documents
• References
• Documents require a unique _id field that acts as a primary key
19
Data Models
• Denormalized
• Better read performance
• Single atomic write operation
• Document growth
• Dot notation
20
Embedded Data Models
Data Model
• One-to-One Relationship
21
Embedded Data Models
{
_id: "infasla",
name: "Anthony Slabinck",
address: {
street: "123 Fake Street",
city: "Faketon",
state: "MA",
zip: "12345"
}
}
Data Model
• One-to-Many Relationship
22
Embedded Data Models
{
_id: "infasla",
name: "Anthony Slabinck",
addresses: [
{ street: "123 Fake Street",
city: "Faketon",
state: "MA",
zip: "12345" },
{ street: "1 Other Street",
city: "Boston",
state: "MA",
zip: "12345"
}
]
}
Data Model
• Normalized
• Duplication of data
• Complex many-to-many
relationships
• Follow-up queries
23
References
Data Model
• One-to-Many Relationship
{ _id: "oreilly",
name: "O'Reilly Media",
founded: 1980,
location: "CA"
}
{ _id: 123456789,
title: "MongoDB: The Definitive Guide",
author: [ "Kristina Chodorow", "Mike Dirolf" ],
published_date: ISODate("2010-09-24"),
pages: 216,
language: "English",
publisher_id: "oreilly"
}
{ _id: 234567890,
title: "50 Tips and Tricks for MongoDB Developer",
author: "Kristina Chodorow",
published_date: ISODate("2011-05-06"),
pages: 68,
language: "English",
publisher_id: "oreilly"
}
24
References
Model Tree Structures
• Parent references
• Child references
• Array of Ancestors
• Materialized Paths
db.categories.insert( { _id: "MongoDB", parent: "Databases" } )
db.categories.insert( { _id: "dbm", parent: "Databases" } )
db.categories.insert( { _id: "Databases", parent: "Programming" } )
db.categories.insert( { _id: "Languages", parent: "Programming" } )
db.categories.insert( { _id: "Programming", parent: "Books" } )
db.categories.insert( { _id: "Books", parent: null } )
25
GridFS
• BSON-document size limit of 16MB
• Divides a file into parts, or chunks and stores each of those chunks as
a separate document
• Two collections
• File chunks
• File metadata
• Reassemble chunks as needed
26
Capped Collections
• Fixed-size collections
• Insert and retrieve documents based on insertion order
• Automatically removes the oldest document
• Ideal for logging
27
Aggregation
• Operations that process data records and return computed results
• Simplifies application code
• Limits resource requirements
• Aggregation modalities
• Aggregation pipelines
• Map-Reduce
• Single purpose aggregation operations
28
Aggregation
• Stages
• Preferred method
29
Aggregation pipelines
Aggregation
• Two phases
• JavaScript functions
• Less efficient and more
complex than the aggregation
pipeline
30
Map-Reduce
Aggregation
• Simple
• Count
• Distinct
• Grouping
31
Single purpose aggregation operations
Indexes
• Efficient execution of queries
• Data structure
• Stores the value of a specific
field or set of fields, ordered by
value the field
• Create indexes that support
your common and user-facing
queries
32
Indexes
• Default _id
• Single Field
• Compound Index
• Multikey Index
• Geospatial Index
• Text Indexes
• Hashed Indexes
33
Types
Indexes
• Unique Indexes
• Sparse Indexes
• TTL Indexes
34
Properties
Indexes
• db.people.ensureIndex( { zipcode: 1 } )
• db.people.ensureIndex( { zipcode: 1 }, { background: true } )
• db.people.ensureIndex( { zipcode: 1 }, { background: true, sparse: true } )
• db.accounts.ensureIndex( { username: 1 }, { unique: true, dropDups: true } )
35
Creation
Replication
• What?
• Synchronizing data across multiple servers
• Purpose?
• Provides redundancy and increases data availability
36
Replication
• A group of mongod instances
that host the same data set
• Primary receives all write
operations
• Primary logs all changes in its
oplog
• Secondaries apply operations
from the primary
37
Replica set
Replication
• Arbiter
• Does not maintain a data set
• Only exits to vote
38
Replica set
Replication
39
Replica set
• Automatic failover
Replication
• Additional features:
• Read preference
• Priority
• Hidden members
• Delayed members
40
Replica set
Sharding
• What?
• Storing data across multiple machines
• When?
• High query rates exhaust the CPU capacity of the server
• Larger data sets exceed the storage capacity of a single machine
• Working set sizes larger than the system’s RAM stress the I/O capacity of
disk drives
41
Sharding
• Adds more CPU and storage
42
Vertical scaling – scale up
Scale
Price
Sharding
• Distributes the data
43
Horizontal scaling – scale outPrice
Scale
Sharding
• Shards store the data
• Query Routers interface with
client applications and direct
operations
• Config servers store the
cluster’s metadata
44
Sharded cluster
Sharding
• Collection level
• Shard key
• Indexed field or an indexed
compound field that exists in
every document
• Chunks
• Range based partitioning
• Hash based partitioning
• Automatic balancing
45
Data partitioning
MongoDB Architecture
46
MongoDB at scale
• Cluster scale
• Distributing across 100+ nodes in multiple data centers
• Performance scale
• 100K+ database reads and writes per second while maintaining strict SLAs
• Data scale
• Storing 1B+ documents in the database
47
Metrics
Lower TCO
• Dev/Ops savings
• Ease of use
• Fast, iterative development
• Hardware savings
• Commodity hardware
• Scale out
• Software/Support savings
• No upfront licence
48
Relational database
POJO Mappers
• Morphia
• Spring Data MongoDB
• Hibernate OGM
49
Resources
• http://docs.mongodb.org/manual/
• https://university.mongodb.com/
• M101J: MongoDB for Java Developers
• M102: MongoDB for DBAs
50
Building an App with MongoDB
51
Demo
Questions?
52

Contenu connexe

Tendances

Common MongoDB Use Cases
Common MongoDB Use CasesCommon MongoDB Use Cases
Common MongoDB Use Cases
DATAVERSITY
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
Kai Zhao
 
Introduction to NoSQL Databases
Introduction to NoSQL DatabasesIntroduction to NoSQL Databases
Introduction to NoSQL Databases
Derek Stainer
 

Tendances (20)

Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptx
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Common MongoDB Use Cases
Common MongoDB Use CasesCommon MongoDB Use Cases
Common MongoDB Use Cases
 
MongoDB WiredTiger Internals
MongoDB WiredTiger InternalsMongoDB WiredTiger Internals
MongoDB WiredTiger Internals
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
 
MongodB Internals
MongodB InternalsMongodB Internals
MongodB Internals
 
Faster, better, stronger: The new InnoDB
Faster, better, stronger: The new InnoDBFaster, better, stronger: The new InnoDB
Faster, better, stronger: The new InnoDB
 
NoSQL databases
NoSQL databasesNoSQL databases
NoSQL databases
 
Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
 
Migrating from RDBMS to MongoDB
Migrating from RDBMS to MongoDBMigrating from RDBMS to MongoDB
Migrating from RDBMS to MongoDB
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDB
 
Introducing Delta Live Tables: Make Reliable ETL Easy on Delta Lake
Introducing Delta Live Tables: Make Reliable ETL Easy on Delta LakeIntroducing Delta Live Tables: Make Reliable ETL Easy on Delta Lake
Introducing Delta Live Tables: Make Reliable ETL Easy on Delta Lake
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
Copy of MongoDB .pptx
Copy of MongoDB .pptxCopy of MongoDB .pptx
Copy of MongoDB .pptx
 
Mongo db dhruba
Mongo db dhrubaMongo db dhruba
Mongo db dhruba
 
MongoDB.pptx
MongoDB.pptxMongoDB.pptx
MongoDB.pptx
 
Introduction to NoSQL Databases
Introduction to NoSQL DatabasesIntroduction to NoSQL Databases
Introduction to NoSQL Databases
 
An Enterprise Architect's View of MongoDB
An Enterprise Architect's View of MongoDBAn Enterprise Architect's View of MongoDB
An Enterprise Architect's View of MongoDB
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDB
 

En vedette

MongoDB- Crud Operation
MongoDB- Crud OperationMongoDB- Crud Operation
MongoDB- Crud Operation
Edureka!
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Edureka!
 
Introduction to column oriented databases
Introduction to column oriented databasesIntroduction to column oriented databases
Introduction to column oriented databases
ArangoDB Database
 
Big Data Analytics 3: Machine Learning to Engage the Customer, with Apache Sp...
Big Data Analytics 3: Machine Learning to Engage the Customer, with Apache Sp...Big Data Analytics 3: Machine Learning to Engage the Customer, with Apache Sp...
Big Data Analytics 3: Machine Learning to Engage the Customer, with Apache Sp...
MongoDB
 

En vedette (20)

MongoDB quickstart for Java, PHP, and Python developers
MongoDB quickstart for Java, PHP, and Python developersMongoDB quickstart for Java, PHP, and Python developers
MongoDB quickstart for Java, PHP, and Python developers
 
Introduction to MongoDB and Workshop
Introduction to MongoDB and WorkshopIntroduction to MongoDB and Workshop
Introduction to MongoDB and Workshop
 
MongoDB gridfs
MongoDB gridfsMongoDB gridfs
MongoDB gridfs
 
Getting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJSGetting Started with MongoDB and NodeJS
Getting Started with MongoDB and NodeJS
 
MongoDB Operations for Developers
MongoDB Operations for DevelopersMongoDB Operations for Developers
MongoDB Operations for Developers
 
MongoDB Internals
MongoDB InternalsMongoDB Internals
MongoDB Internals
 
Webinar: Data Processing and Aggregation Options
Webinar: Data Processing and Aggregation OptionsWebinar: Data Processing and Aggregation Options
Webinar: Data Processing and Aggregation Options
 
Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo db
 
MongoDB - Ekino PHP
MongoDB - Ekino PHPMongoDB - Ekino PHP
MongoDB - Ekino PHP
 
MongoDB- Crud Operation
MongoDB- Crud OperationMongoDB- Crud Operation
MongoDB- Crud Operation
 
Gridfs and MongoDB
Gridfs and MongoDBGridfs and MongoDB
Gridfs and MongoDB
 
Introduction to MongoDB with PHP
Introduction to MongoDB with PHPIntroduction to MongoDB with PHP
Introduction to MongoDB with PHP
 
MongoDB on EC2 and EBS
MongoDB on EC2 and EBSMongoDB on EC2 and EBS
MongoDB on EC2 and EBS
 
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Dan Sullivan - Data Analytics and Text Mining with MongoDB - NoSQL matters Du...
Dan Sullivan - Data Analytics and Text Mining with MongoDB - NoSQL matters Du...Dan Sullivan - Data Analytics and Text Mining with MongoDB - NoSQL matters Du...
Dan Sullivan - Data Analytics and Text Mining with MongoDB - NoSQL matters Du...
 
Introduction to column oriented databases
Introduction to column oriented databasesIntroduction to column oriented databases
Introduction to column oriented databases
 
Big Data Analytics 3: Machine Learning to Engage the Customer, with Apache Sp...
Big Data Analytics 3: Machine Learning to Engage the Customer, with Apache Sp...Big Data Analytics 3: Machine Learning to Engage the Customer, with Apache Sp...
Big Data Analytics 3: Machine Learning to Engage the Customer, with Apache Sp...
 
An Introduction to Map/Reduce with MongoDB
An Introduction to Map/Reduce with MongoDBAn Introduction to Map/Reduce with MongoDB
An Introduction to Map/Reduce with MongoDB
 
MongoDB & Machine Learning
MongoDB & Machine LearningMongoDB & Machine Learning
MongoDB & Machine Learning
 

Similaire à MongoDB

MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Rails
rfischer20
 
Mongo db eveningschemadesign
Mongo db eveningschemadesignMongo db eveningschemadesign
Mongo db eveningschemadesign
MongoDB APAC
 
MongoDB Tick Data Presentation
MongoDB Tick Data PresentationMongoDB Tick Data Presentation
MongoDB Tick Data Presentation
MongoDB
 
Building your First MEAN App
Building your First MEAN AppBuilding your First MEAN App
Building your First MEAN App
MongoDB
 

Similaire à MongoDB (20)

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongoDB Basics
MongoDB BasicsMongoDB Basics
MongoDB Basics
 
No SQL : Which way to go? Presented at DDDMelbourne 2015
No SQL : Which way to go?  Presented at DDDMelbourne 2015No SQL : Which way to go?  Presented at DDDMelbourne 2015
No SQL : Which way to go? Presented at DDDMelbourne 2015
 
NoSQL, which way to go?
NoSQL, which way to go?NoSQL, which way to go?
NoSQL, which way to go?
 
MongoDB Pros and Cons
MongoDB Pros and ConsMongoDB Pros and Cons
MongoDB Pros and Cons
 
Agility and Scalability with MongoDB
Agility and Scalability with MongoDBAgility and Scalability with MongoDB
Agility and Scalability with MongoDB
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Rails
 
Mongo db eveningschemadesign
Mongo db eveningschemadesignMongo db eveningschemadesign
Mongo db eveningschemadesign
 
MongoDB Tick Data Presentation
MongoDB Tick Data PresentationMongoDB Tick Data Presentation
MongoDB Tick Data Presentation
 
10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup
 
Mongo db tutorials
Mongo db tutorialsMongo db tutorials
Mongo db tutorials
 
MongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewMongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overview
 
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
 
Webinar: When to Use MongoDB
Webinar: When to Use MongoDBWebinar: When to Use MongoDB
Webinar: When to Use MongoDB
 
Python Ireland Conference 2016 - Python and MongoDB Workshop
Python Ireland Conference 2016 - Python and MongoDB WorkshopPython Ireland Conference 2016 - Python and MongoDB Workshop
Python Ireland Conference 2016 - Python and MongoDB Workshop
 
MongoDB Scalability Best Practices
MongoDB Scalability Best PracticesMongoDB Scalability Best Practices
MongoDB Scalability Best Practices
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behl
 
MongoDB_ppt.pptx
MongoDB_ppt.pptxMongoDB_ppt.pptx
MongoDB_ppt.pptx
 
Building your First MEAN App
Building your First MEAN AppBuilding your First MEAN App
Building your First MEAN App
 

Dernier

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

MongoDB

  • 1. MongoDB (for Java Developers) Anthony Slabinck
  • 2. Who am I? • Internship at Provikmo • 3 years 6 months • Competitive cyclist
  • 3. What is MongoDB? • The leading NoSQL database (http://db-engines.com/en/) • Open source • Non-relational JSON document store • BSON (Binary JSON) • Dynamic schema • Agile • Scalable through replicaton and sharding 3
  • 4. The leading NoSQL database 4 • LinkedIn Job Skills • Google Search • Indeed.com Trends
  • 5. MongoDB relative to relational databases 5
  • 7. By use case • Single View • Internet of Things • Mobile • Real-Time Analytics • Personalization • Content Management • Catalog 7
  • 8. From relational databases to MongoDB 8 { first_name: "Anthony", surname: "Slabinck", city: "Bruges", location: [45.123,47.232], cars: [ { model: "Bentley", year: 1973, value: 100000 }, { mode: "Rolls Royce", year: 1965, value: 330000 } ] }
  • 9. MongoDB is full featured 9
  • 14. MongoDB CRUD Operations 14 Write operations - insert
  • 15. MongoDB CRUD Operations 15 Write operations - update
  • 16. MongoDB CRUD Operations 16 Write operations - remove
  • 17. Installation • Download MongoDB from http://www.mongodb.org/downloads • Download the Java Driver (maven) • mongod • Daemon process • mongo • Interactive JavaScript shell interface • Robomongo • Cross-platform management tool 17
  • 18. Getting started with MongoDB 18 Demo
  • 19. Data Models • Flexible schema • Collections do not enforce document structure • Consider how applications will use your database • No foreign keys, no joins • Relationships between data • Embedded documents • References • Documents require a unique _id field that acts as a primary key 19
  • 20. Data Models • Denormalized • Better read performance • Single atomic write operation • Document growth • Dot notation 20 Embedded Data Models
  • 21. Data Model • One-to-One Relationship 21 Embedded Data Models { _id: "infasla", name: "Anthony Slabinck", address: { street: "123 Fake Street", city: "Faketon", state: "MA", zip: "12345" } }
  • 22. Data Model • One-to-Many Relationship 22 Embedded Data Models { _id: "infasla", name: "Anthony Slabinck", addresses: [ { street: "123 Fake Street", city: "Faketon", state: "MA", zip: "12345" }, { street: "1 Other Street", city: "Boston", state: "MA", zip: "12345" } ] }
  • 23. Data Model • Normalized • Duplication of data • Complex many-to-many relationships • Follow-up queries 23 References
  • 24. Data Model • One-to-Many Relationship { _id: "oreilly", name: "O'Reilly Media", founded: 1980, location: "CA" } { _id: 123456789, title: "MongoDB: The Definitive Guide", author: [ "Kristina Chodorow", "Mike Dirolf" ], published_date: ISODate("2010-09-24"), pages: 216, language: "English", publisher_id: "oreilly" } { _id: 234567890, title: "50 Tips and Tricks for MongoDB Developer", author: "Kristina Chodorow", published_date: ISODate("2011-05-06"), pages: 68, language: "English", publisher_id: "oreilly" } 24 References
  • 25. Model Tree Structures • Parent references • Child references • Array of Ancestors • Materialized Paths db.categories.insert( { _id: "MongoDB", parent: "Databases" } ) db.categories.insert( { _id: "dbm", parent: "Databases" } ) db.categories.insert( { _id: "Databases", parent: "Programming" } ) db.categories.insert( { _id: "Languages", parent: "Programming" } ) db.categories.insert( { _id: "Programming", parent: "Books" } ) db.categories.insert( { _id: "Books", parent: null } ) 25
  • 26. GridFS • BSON-document size limit of 16MB • Divides a file into parts, or chunks and stores each of those chunks as a separate document • Two collections • File chunks • File metadata • Reassemble chunks as needed 26
  • 27. Capped Collections • Fixed-size collections • Insert and retrieve documents based on insertion order • Automatically removes the oldest document • Ideal for logging 27
  • 28. Aggregation • Operations that process data records and return computed results • Simplifies application code • Limits resource requirements • Aggregation modalities • Aggregation pipelines • Map-Reduce • Single purpose aggregation operations 28
  • 29. Aggregation • Stages • Preferred method 29 Aggregation pipelines
  • 30. Aggregation • Two phases • JavaScript functions • Less efficient and more complex than the aggregation pipeline 30 Map-Reduce
  • 31. Aggregation • Simple • Count • Distinct • Grouping 31 Single purpose aggregation operations
  • 32. Indexes • Efficient execution of queries • Data structure • Stores the value of a specific field or set of fields, ordered by value the field • Create indexes that support your common and user-facing queries 32
  • 33. Indexes • Default _id • Single Field • Compound Index • Multikey Index • Geospatial Index • Text Indexes • Hashed Indexes 33 Types
  • 34. Indexes • Unique Indexes • Sparse Indexes • TTL Indexes 34 Properties
  • 35. Indexes • db.people.ensureIndex( { zipcode: 1 } ) • db.people.ensureIndex( { zipcode: 1 }, { background: true } ) • db.people.ensureIndex( { zipcode: 1 }, { background: true, sparse: true } ) • db.accounts.ensureIndex( { username: 1 }, { unique: true, dropDups: true } ) 35 Creation
  • 36. Replication • What? • Synchronizing data across multiple servers • Purpose? • Provides redundancy and increases data availability 36
  • 37. Replication • A group of mongod instances that host the same data set • Primary receives all write operations • Primary logs all changes in its oplog • Secondaries apply operations from the primary 37 Replica set
  • 38. Replication • Arbiter • Does not maintain a data set • Only exits to vote 38 Replica set
  • 40. Replication • Additional features: • Read preference • Priority • Hidden members • Delayed members 40 Replica set
  • 41. Sharding • What? • Storing data across multiple machines • When? • High query rates exhaust the CPU capacity of the server • Larger data sets exceed the storage capacity of a single machine • Working set sizes larger than the system’s RAM stress the I/O capacity of disk drives 41
  • 42. Sharding • Adds more CPU and storage 42 Vertical scaling – scale up Scale Price
  • 43. Sharding • Distributes the data 43 Horizontal scaling – scale outPrice Scale
  • 44. Sharding • Shards store the data • Query Routers interface with client applications and direct operations • Config servers store the cluster’s metadata 44 Sharded cluster
  • 45. Sharding • Collection level • Shard key • Indexed field or an indexed compound field that exists in every document • Chunks • Range based partitioning • Hash based partitioning • Automatic balancing 45 Data partitioning
  • 47. MongoDB at scale • Cluster scale • Distributing across 100+ nodes in multiple data centers • Performance scale • 100K+ database reads and writes per second while maintaining strict SLAs • Data scale • Storing 1B+ documents in the database 47 Metrics
  • 48. Lower TCO • Dev/Ops savings • Ease of use • Fast, iterative development • Hardware savings • Commodity hardware • Scale out • Software/Support savings • No upfront licence 48 Relational database
  • 49. POJO Mappers • Morphia • Spring Data MongoDB • Hibernate OGM 49
  • 50. Resources • http://docs.mongodb.org/manual/ • https://university.mongodb.com/ • M101J: MongoDB for Java Developers • M102: MongoDB for DBAs 50
  • 51. Building an App with MongoDB 51 Demo