Webinar: Getting Started with MongoDB - Back to Basics

30
Application Development Series Back to Basics – Introduction Daniel Roberts @dmroberts #MongoDBBasics

description

Part one an Introduction to MongoDB. Learn how easy it is to start building applications with MongoDB. This session covers key features and functionality of MongoDB and sets out the course of building an application.

Transcript of Webinar: Getting Started with MongoDB - Back to Basics

Page 1: Webinar: Getting Started with MongoDB - Back to Basics

Application Development SeriesBack to Basics – Introduction

Daniel Roberts@dmroberts

#MongoDBBasics

Page 2: Webinar: Getting Started with MongoDB - Back to Basics

2

• About the Webinar Series

• Data Model

• Query Model

• Scalability

• Availability

• Deployment Architectures

• Performance

• Next Session

Introduction

Page 3: Webinar: Getting Started with MongoDB - Back to Basics

3

• Split into 2 sections– Application Development (4 parts)

• Schema Design• Interacting with the database query and update operators• Indexing• Reporting

– Operations (3 parts)• Deployment – scale out and high availability• Monitoring and performance tuning• Backup and recovery

Series Outline & Approach

Page 4: Webinar: Getting Started with MongoDB - Back to Basics

4

• 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 5: Webinar: Getting Started with MongoDB - Back to Basics

5

• 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 6: Webinar: Getting Started with MongoDB - Back to Basics

MongoDB

Page 7: Webinar: Getting Started with MongoDB - Back to Basics

7

Operational Database

Page 8: Webinar: Getting Started with MongoDB - Back to Basics

8

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 9: Webinar: Getting Started with MongoDB - Back to Basics

9

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 10: Webinar: Getting Started with MongoDB - Back to Basics

10

Simplify development

Page 11: Webinar: Getting Started with MongoDB - Back to Basics

11

Simplify development

Page 12: Webinar: Getting Started with MongoDB - Back to Basics

12

Rich database interaction

Page 13: Webinar: Getting Started with MongoDB - Back to Basics

Query Model

Page 14: Webinar: Getting Started with MongoDB - Back to Basics

14

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 15: Webinar: Getting Started with MongoDB - Back to Basics

15

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 16: Webinar: Getting Started with MongoDB - Back to Basics

16

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 17: Webinar: Getting Started with MongoDB - Back to Basics

17

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 18: Webinar: Getting Started with MongoDB - Back to Basics

18

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 19: Webinar: Getting Started with MongoDB - Back to Basics

Scalability

Page 20: Webinar: Getting Started with MongoDB - Back to Basics

20

Automatic Sharding

• Three types of sharding: hash-based, range-based, tag-aware

• Increase or decrease capacity as you go

• Automatic balancing

Page 21: Webinar: Getting Started with MongoDB - Back to Basics

21

Query Routing

• Multiple query optimization models

• Each sharding option appropriate for different apps

Page 22: Webinar: Getting Started with MongoDB - Back to Basics

Availability

Page 23: Webinar: Getting Started with MongoDB - Back to Basics

23

• 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 24: Webinar: Getting Started with MongoDB - Back to Basics

24

Replica Sets

• Replica Set – two or more copies

• “Self-healing” shard

• Addresses many concerns:

- High Availability

- Disaster Recovery

- Maintenance

Page 25: Webinar: Getting Started with MongoDB - Back to Basics

25

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 26: Webinar: Getting Started with MongoDB - Back to Basics

Performance

Page 27: Webinar: Getting Started with MongoDB - Back to Basics

27

Better Data Locality

Performance

In-Memory Caching

In-Place Updates

Page 28: Webinar: Getting Started with MongoDB - Back to Basics

28

• 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 29: Webinar: Getting Started with MongoDB - Back to Basics

29

• Matt Bates – 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 – 6th February

Page 30: Webinar: Getting Started with MongoDB - Back to Basics