Mongo db japan

38
Roger Bodamer @rogerb

description

Tokyo, nov 1st 2010.

Transcript of Mongo db japan

Page 1: Mongo db japan

Roger Bodamer @rogerb

Page 2: Mongo db japan

Baseball World Series

Giants lead 3-1 over Rangers

Page 3: Mongo db japan

What is MongoDB?

quick introductiondesign session

deploy mongodbscaling

Page 4: Mongo db japan

MongoDB adoption is very strong

90,000 Database downloads per month

Page 5: Mongo db japan

Over 1,000 Production Deployments

Page 6: Mongo db japan

Platform and Language supportMongoDB is Implemented in C++ for best performance

Platforms 32/64 bit• Windows• Linux, Mac OS-X, FreeBSD, Solaris

Page 7: Mongo db japan

Platform and Language supportMongoDB is Implemented in C++ for best performance

Platforms 32/64 bit• Windows• Linux, Mac OS-X, FreeBSD, Solaris

Language drivers for• Ruby / Ruby-on-Rails • Java / C# / JavaScript• C / C++• Erlang • Python, Perl• others...

.. and much more ! ..

Page 8: Mongo db japan

non-­‐relational,  next-­‐generation  operational  datastores  and  databases

NoSQL Really Means:

Page 9: Mongo db japan

RDBMS(Oracle,  MySQL)

Page 10: Mongo db japan

RDBMS(Oracle,  MySQL)

New Gen. OLAP

(vertica,  aster,  greenplum)

Page 11: Mongo db japan

RDBMS(Oracle,  MySQL)

New Gen. OLAP

(vertica,  aster,  greenplum)

Non-relationalOperational

Stores(“NoSQL”)

Page 12: Mongo db japan

Philosophy:  maximize  features  -­‐  up  to  the  “knee”  in  the  curve,  then  stop

depth  of  functionality

scalab

ility  &  perform

ance •memcached

• key/value

• RDBMS

Page 13: Mongo db japan

Horizontally ScalableArchitectures

no  joinsno  complex  transactions+

Page 14: Mongo db japan

New Data Models

no  joinsno  complex  transactions+

Page 15: Mongo db japan

Improved ways to develop

New Data Models-­‐>  

Page 16: Mongo db japan

Terminology

RDBMS MongoDB

Table Collection

Row(s) JSON  Document

Index Index

Join Embedding  &  Linking

Partition Shard

Partition  Key Shard  Key

Page 17: Mongo db japan

MongoDB Design Session

Page 18: Mongo db japan

MongoDB Design SessionBlog Post Document

 p  =  {author:  “roger”,                date:  new  Date(),                text:  “Spirited  Away”,                tags:  [“Tezuka”,  “Manga”]}

>db.posts.save(p)

Page 19: Mongo db japan

Query Posts Collection

>db.posts.find()

{ _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "roger", date : "Sat Jul 24 2010 19:47:11 GMT-0700 (PDT)", text : "Spirited Away", tags : [ "Tezuka", "Manga" ] } Notes: - _id is unique, but can be anything you’d like

Page 20: Mongo db japan

Create index on any Field in Document

// 1 means ascending, -1 means descending

>db.posts.ensureIndex({author: 1})

>db.posts.find({author: 'roger'}) { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "roger", ... }

Secondary Index

Page 21: Mongo db japan

Query operatorsConditional operators: $ne, $in, $nin, $mod, $all, $size, $exists, $type, .. $lt, $lte, $gt, $gte, $ne, ...

// find posts with any tags >db.posts.find({tags: {$exists: true}})

Page 22: Mongo db japan

Query operatorsConditional operators: $ne, $in, $nin, $mod, $all, $size, $exists, $type, .. $lt, $lte, $gt, $gte, $ne,

// find posts with any tags >db.posts.find({tags: {$exists: true}})

Regular expressions: // posts where author starts with r >db.posts.find({author: /^r*/i })

Page 23: Mongo db japan

Query operatorsConditional operators: $ne, $in, $nin, $mod, $all, $size, $exists, $type, .. $lt, $lte, $gt, $gte, $ne,

// find posts with any tags >db.posts.find({tags: {$exists: true}})

Regular expressions: // posts where author starts with k >db.posts.find({author: /^k*/i })

Counting: // posts written by roger    >db.posts.find({author:  “roger”}).count()

Page 24: Mongo db japan

Extending the Schema comment = {author: “fred”, date: new Date(), text: “Best Movie Ever”}

update = { ‘$push’: {comments: comment}}

 >db.posts.update({_id:  “...”  },  update)

Adding Comments to Blog

Page 25: Mongo db japan

{ _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "roger", date : "Sat Jul 24 2010 19:47:11 GMT-0700 (PDT)", text : "Spirited Away", tags : [ "Tezuka", "Manga" ], comments : [ { author : "Fred", date : "Sat Jul 24 2010 20:51:03 GMT-0700 (PDT)", text : "Best Movie Ever" } ]}

Page 26: Mongo db japan

// create index on nested documents: >db.posts.ensureIndex({"comments.author": 1})

>db.posts.find({comments.author:”Fred”})

Secondary Index

Page 27: Mongo db japan

Deploying MongoDB

Page 28: Mongo db japan

Deploying MongoDB

Primary

Read  /  Write

Page 29: Mongo db japan

Deploying MongoDB

Primary

Secondary

Read  /  Write

Replication

Page 30: Mongo db japan

Setting Up MongoDB

Primary

Secondary

Read  /  Write

Secondary  for  Backup

Replication

Replication

Page 31: Mongo db japan

Setting Up MongoDB

Primary

Secondary

Read  /  Write

Secondary  for  Backup

Read Replication

Replication

Page 32: Mongo db japan

Setting Up MongoDB

Primary

Secondary

Read  /  Write

Secondary  for  Backup

Read Replication

Replication

Replicaset

Page 33: Mongo db japan

Read Scalability : Replication

write

read

ReplicaSet  1

Primary

Secondary

Secondary

Page 34: Mongo db japan

Write Scalability: Sharding

write

read

ReplicaSet  1

Primary

Secondary

Secondary

ReplicaSet  2

Primary

Secondary

Secondary

ReplicaSet  3

Primary

Secondary

Secondary

key  range  0  ..  30

key  range  31  ..  60

key  range  61  ..  100

Page 35: Mongo db japan

Monitoring

• We like Munin ..• ... but other frameworks work as well

• Primary function: • Measure stats over time• Tells you what is going on with your system

Page 36: Mongo db japan

MongoDB makes building applications easy

Designed a Blog SchemaEvolved the SchemaDeployed MongoDB

Scale MongoDB

Page 37: Mongo db japan

MongoDB makes building applications easy

Map / ReduceCapped CollectionsTail-able Cursors

Geo Indexing

.. and much more ! ..

Page 38: Mongo db japan

@mongodb

conferences,  appearances,  and  meetupshttp://www.10gen.com/events

http://bit.ly/mongoG  Facebook                    |                  Twitter                  |                  LinkedIn

http://linkd.in/joinmongo

download at mongodb.org

We’re Hiring [email protected]