s01 e00 einfuehrung-in_mongodb
TRANSCRIPT
![Page 1: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/1.jpg)
Staffel 1: MongoDB Applikationsentwicklung
Marc Schwering@m4rcsch
#MongoDBBasics
Einführung in MongoDB – “Back to Basics”
![Page 2: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/2.jpg)
2
• Fragen im Chat oder via Twitter: #MonogDBBasics
• Das Webinar ist auf deutsch, die Folien sind in englisch
• Die Serie wird ist in zwei Staffeln gegliedert– Applikationsentwicklung mit MongoDB– MongoDB in produktion / „operations“
• Das Webinar wird aufgezeichnet
Generelle Informationen
![Page 3: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/3.jpg)
3
• About the Webinar Series • Data Model• Query Model• Scalability• Availability• Deployment Architectures• Performance• Next Session
Introduction
![Page 4: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/4.jpg)
4
• Split into 2 seasons– Application Development (4 parts)
• Schema Design• Interacting with the database query and update operators• Indexing• Aggregation & Reporting
– Operations (3 parts)• Deployment – scale out and high availability• Monitoring and performance tuning• Backup and recovery
Series Outline & Approach
![Page 5: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/5.jpg)
5
• Content Management System– Will utilise :
• Query & update operators• Aggregation Framework• Geospatial queries• Pre Aggregated reports for fast analytics• Polymorphic documents• And more…
• Take away framework• An approach that you can reuse in your own
applications
Application Overview
![Page 6: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/6.jpg)
6
• Virtual Genius Bar
– Use the chat to post questions
– EMEA Solution Architecture team are on hand
– Make use of them during the sessions!!!
Q & A
![Page 7: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/7.jpg)
MongoDB
![Page 8: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/8.jpg)
8
Operational Database
![Page 9: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/9.jpg)
9
Document Data Model
Relational - Tables{ first_name: ‘Paul’, surname: ‘Miller’, city: ‘London’, location: {
type: “Point”, coordinates :
[-0.128, 51.507]
}, cars: [ { model: ‘Bentley’, year: 1973, value: 100000, … }, { model: ‘Rolls Royce’, year: 1965, value: 330000, … } }}
Document - Collections
![Page 10: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/10.jpg)
10
Document Model
• Agility and flexibility – dynamic schema– Data models can evolve easily
– Companies can adapt to changes quickly
• Intuitive, natural data representation– Remove impedance mismatch
– Many types of applications are a good fit
• Reduces the need for joins, disk seeks– Programming is more simple
– Performance can be delivered at scale
![Page 11: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/11.jpg)
11
Simplify development
![Page 12: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/12.jpg)
12
Simplify development
![Page 13: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/13.jpg)
13
Rich database interaction
![Page 14: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/14.jpg)
Query Model
![Page 15: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/15.jpg)
15
ShellCommand-line shell for interacting directly with database
Shell and Drivers
DriversDrivers for most popular programming languages and frameworks
> db.collection.insert({company:“10gen”, product:“MongoDB”})> > db.collection.findOne(){
“_id” : ObjectId(“5106c1c2fc629bfe52792e86”),
“company” : “10gen”“product” : “MongoDB”
}
Java
Python
Perl
Ruby
Haskell
JavaScript
![Page 16: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/16.jpg)
16
MongoDB is full featured
Queries• Find Paul’s cars• Find everybody in London with a car
built between 1970 and 1980
Geospatial • Find all of the car owners within 5km of Trafalgar Sq.
Text Search • Find all the cars described as having leather seats
Aggregation • Calculate the average value of Paul’s car collection
Map Reduce• What is the ownership pattern of colors
by geography over time? (is purple trending up in China?)
{ first_name: ‘Paul’, surname: ‘Miller’, city: ‘London’, location: {
type: “Point”, coordinates :
[-0.128, 51.507]
}, cars: [ { model: ‘Bentley’, year: 1973, value: 100000, … }, { model: ‘Rolls Royce’, year: 1965, value: 330000, … } }}
![Page 17: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/17.jpg)
17
Query Example
Rich Queries• Find Paul’s cars• Find everybody in London with a car
built between 1970 and 1980
db.cars.find({first_name: ‘Paul’
})
db.cars.find({city: ‘London’, ”cars.year" : {
$gte : 1970, $lte : 1980
}})
{ first_name: ‘Paul’, surname: ‘Miller’, city: ‘London’, location: {
type: “Point”, coordinates :
[-0.128, 51.507]
}, cars: [ { model: ‘Bentley’, year: 1973, value: 100000, … }, { model: ‘Rolls Royce’, year: 1965, value: 330000, … } }}
![Page 18: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/18.jpg)
18
Geo Spatial Example
db.cars.find( { location:
{ $near : { $geometry : { type: 'Point' , coordinates :
[-0.128, 51.507] }
}, $maxDistance :5000 } } )
Geospatial • Find all of the car owners within 5km of Trafalgar Sq.
{ first_name: ‘Paul’, surname: ‘Miller’, city: ‘London’, location: {
type: “Point”, coordinates :
[-0.128, 51.507]
}, cars: [ { model: ‘Bentley’, year: 1973, value: 100000, … }, { model: ‘Rolls Royce’, year: 1965, value: 330000, … } }}
![Page 19: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/19.jpg)
19
Aggregation Framework Example
db.cars.aggregate( [
{$match : {"first_name" : "Paul"}}, {$project : {"first_name":1,"cars":1}},{$unwind : "$cars"},{ $group : {_id:"$first_name",
average : {
$avg : "$cars.value"}}} ])
{ "_id" : "Paul", "average" : 215000 }
Aggregation • Calculate the average value of Paul’s car collection
{ first_name: ‘Paul’, surname: ‘Miller’, city: ‘London’, location: {
type: “Point”, coordinates :
[-0.128, 51.507]
}, cars: [ { model: ‘Bentley’, year: 1973, value: 100000, … }, { model: ‘Rolls Royce’, year: 1965, value: 330000, … } }}
![Page 20: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/20.jpg)
Scalability
![Page 21: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/21.jpg)
21
Automatic Sharding
• Three types of sharding: hash-based, range-based, tag-aware
• Increase or decrease capacity as you go
• Automatic balancing
![Page 22: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/22.jpg)
22
Query Routing
• Multiple query optimization models
• Each sharding option appropriate for different apps
![Page 23: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/23.jpg)
Availability
![Page 24: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/24.jpg)
24
• High Availability – Ensure application availability during many types of failures
• Disaster Recovery – Address the RTO and RPO goals for business continuity
• Maintenance – Perform upgrades and other maintenance operations with no application downtime
Availability Considerations
![Page 25: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/25.jpg)
25
Replica Sets
• Replica Set – two or more copies
• “Self-healing” shard
• Addresses many concerns:
- High Availability
- Disaster Recovery
- Maintenance
![Page 26: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/26.jpg)
26
Replica Set Benefits
Business Needs Replica Set Benefits
High Availability Automated failover
Disaster Recovery Hot backups offsite
Maintenance Rolling upgrades
Low Latency Locate data near users
Workload Isolation Read from non-primary replicas
Data Privacy Restrict data to physical location
Data Consistency Tunable Consistency
![Page 27: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/27.jpg)
Performance
![Page 28: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/28.jpg)
28
Better Data Locality
Performance
In-Memory Caching
In-Place Updates
![Page 29: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/29.jpg)
29
• Document Model– Simplify development– Simplify scale out– Improve performance
• MongoDB– Rich general purpose database– Built in High Availability and Failover– Built in scale out
Summary
![Page 30: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/30.jpg)
30
• Marc Schwering– Schema design for the CMS application
• Collections• Design decisions
– Application architecture• Example technologies• RESTful interface• We’ve chosen python for the examples
– Code Examples
Next Week – 7th May
![Page 31: S01 e00 einfuehrung-in_mongodb](https://reader035.vdocuments.pub/reader035/viewer/2022081514/58f00a3d1a28ab30448b460f/html5/thumbnails/31.jpg)