mongodb at frozenrails

36
opensource, highperformance, documentoriented database Mike Dirolf 10gen, Inc. @mdirolf http://dirolf.com

Upload: mike-dirolf

Post on 19-May-2015

4.072 views

Category:

Technology


2 download

DESCRIPTION

Introduction to MongoDB given at FrozenRails 2010.

TRANSCRIPT

Page 1: MongoDB at FrozenRails

open-­‐source,  high-­‐performance,  document-­‐oriented  database

Mike  Dirolf      •      10gen,  Inc.      •      @mdirolf      •      http://dirolf.com

Page 2: MongoDB at FrozenRails

RDBMS(Oracle,  MySQL)

New Gen. OLAP(vertica,  aster,  greenplum)

Non-relationalOperational Stores

(“NoSQL”)

Page 3: MongoDB at FrozenRails

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

NoSQL Really Means:

Page 4: MongoDB at FrozenRails

Horizontally ScalableArchitectures

no  joinsno  complex  transactions+

Page 5: MongoDB at FrozenRails

New Data Models

no  joinsno  complex  transactions+

Page 6: MongoDB at FrozenRails

New Data Modelsimproved  ways  to  develop  applications?

Page 7: MongoDB at FrozenRails

Data ModelsKey  /  Value

memcached,  Dynamo

TabularBigTable

Document  OrientedMongoDB,  CouchDB

Page 8: MongoDB at FrozenRails

Focus on performance

depth  of  functionality

scalab

ility  &  perform

ance •memcached

• key/value

• RDBMS

Page 9: MongoDB at FrozenRails

JSON-style Documents

{“hello”:  “world”}

\x16\x00\x00\x00\x02hello\x00\x06\x00\x00\x00world\x00\x00

http://bsonspec.org

represented  as  BSON

Page 10: MongoDB at FrozenRails

Flexible “Schemas”

{“author”:  “mike”,  “text”:  “...”}

{“author”:  “eliot”,  “text”:  “...”,  “tags”:  [“mongodb”]}

Page 11: MongoDB at FrozenRails

Dynamic Queries

Page 12: MongoDB at FrozenRails

Atomic Update Modifiers

Page 13: MongoDB at FrozenRails

Focus on Performance

Page 14: MongoDB at FrozenRails

Replication

master

slave slaveslave

master slave

master slave

master master

slave master

Page 15: MongoDB at FrozenRails

Auto-sharding

client

mongos ...mongos

mongodmongod

mongod mongod

mongod

mongod...

Shards

mongod

mongod

mongod

ConfigServers

Page 16: MongoDB at FrozenRails

Many Supported Platforms / Languages

Page 17: MongoDB at FrozenRails

Best Use Cases

The  WebCaching

The  Web

Scaling  Out

High  Volume

Page 18: MongoDB at FrozenRails

Less Good At

highly  transactional

ad-­‐hoc  business  intelligence

problems  that  require  SQL

Page 19: MongoDB at FrozenRails

A Quick Aside

special  key

present  in  all  documents

unique  across  a  Collection

any  type  you  want

_id

Page 20: MongoDB at FrozenRails

Post

{:author  =>  “mike”,  :date  =>  Time.new,  :text  =>  “my  blog  post...”,  :tags  =>  [“mongodb”,  “ruby”]}

Page 21: MongoDB at FrozenRails

Comment

{:author  =>  “eliot”,  :date  =>  Time.new,  :text  =>  “great  post!”}

Page 22: MongoDB at FrozenRails

New Post

post  =  {:author  =>  “mike”,    :date  =>  Time.new,    :text  =>  “my  blog  post...”,    :tags  =>  [“mongodb”,  “ruby”]}

db[“posts”].save(post)

Page 23: MongoDB at FrozenRails

Embedding a Comment

c  =  {:author  =>  “eliot”,    :date  =>  Time.new,    :text  =>  “great  post!”}

db[“posts”].update({:_id  =>  post[:_id]},                        {:$push  =>  {:comments  =>  c}})

Page 24: MongoDB at FrozenRails

Posts by Author

db[“posts”].find(:author  =>  “mike”)

Page 25: MongoDB at FrozenRails

Last 10 Posts

db[“posts”].find    .sort([[:date,  :desc]])    .limit(10)

Page 26: MongoDB at FrozenRails

Posts Since April 1

april_1  =  Time.utc(2010,  4,  1)

db[“posts”].find(:date  =>  {:$gt  =>  april_1})

Page 27: MongoDB at FrozenRails

Posts Ending With ‘Ruby’

db[“posts”].find(:text  =>  /Ruby$/)

Page 28: MongoDB at FrozenRails

Posts With a Tagdb[“posts”].find(:tags  =>  “mongodb”)

...and Fastdb[“posts”].create_index(“tags”)

(multi-­‐key  indexes)

Page 29: MongoDB at FrozenRails

Indexing / Querying on Embedded Docs

db[“posts”].create_index(“comments.author”)

db[“posts”].find(“comments.author”  =>  “eliot”)

(dot  notation)

Page 30: MongoDB at FrozenRails

Counting Posts

db[“posts”].count

db[“posts”].find(:author  =>  “mike”).count

Page 31: MongoDB at FrozenRails

Basic Paging

page  =  2page_size  =  15

db[“posts”].find.limit(page_size)                                .skip(page  *  page_size)

Page 32: MongoDB at FrozenRails

Migration: Adding Titles

post  =  {:author  =>  “mike”,                :date  =>  Time.new,                :text  =>  “another  blog  post...”,                :tags  =>  [“mongodb”],              :title  =>  “MongoDB  for  Fun  and  Profit”}

post_id  =  db[“posts”].save(post)

(just  start  adding  them)

Page 33: MongoDB at FrozenRails

$gt,  $lt,  $gte,  $lte,  $ne,  $all,  $in,  $nin

$not,  $mod,  $size,  $exists,  $type,  $elemMatch

db[“posts”].find(:$where  =>  “this.author  ==  ‘mike’  ||                                                          this.title  ==  ‘foo’”)

Advanced Queries

Page 34: MongoDB at FrozenRails

MongoMapper, Mongoid, et. al.

Page 35: MongoDB at FrozenRails

Other Cool Stuffaggregation  and  map/reduce

capped  collections

unique  indexes

mongo  shell

GridFS

geo

Page 36: MongoDB at FrozenRails

Download MongoDBhttp://www.mongodb.org

and  let  us  know  what  you  think@mdirolf        @mongodb