NoSQL & MongoDB

35
No-SQL & mongoDB @liushuaikobe

description

A lecture of No-SQL & MongoDB.

Transcript of NoSQL & MongoDB

Page 1: NoSQL & MongoDB

No-SQL & mongoDB@liushuaikobe

Page 2: NoSQL & MongoDB

What’s No-SQL?

Page 3: NoSQL & MongoDB

Strozzi NoSQL(1998)

RDBMS

operator-stream paradigm(PIPE)

a set of shell routines that access normal files of the OS

Carlo Strozzi

Page 4: NoSQL & MongoDB

No-SQL == Not Have SQL

Page 5: NoSQL & MongoDB

No-SQL == Not Have

Structured Query Language

SQL

Page 6: NoSQL & MongoDB

…departs from the relational model altogether; it

should therefore have been called more appropriately 'NoREL'.

Page 7: NoSQL & MongoDB

A meetup@San Francisco ——"open source, distributed, non relational databases”

Organized by Johan Oskarsson(Last.fm)

Google's Bigtable & Amazon's Dynamo

Eric Evans(then in RackSpace) reintroduced “No-SQL”

Page 8: NoSQL & MongoDB

No-SQL == non-relational

Page 9: NoSQL & MongoDB

Eric Evans

My regret however isn't about what the name says, it's about

what it doesn't.

Page 10: NoSQL & MongoDB

no:sql(east) conference@ Atlanta

Page 11: NoSQL & MongoDB

> select fun, profit > from real_world > where relational=false;

Page 12: NoSQL & MongoDB

No-SQL == Not Only SQL

Page 13: NoSQL & MongoDB

CAP Theorem(Eric Brewer)

Consistency

Partition Tolerance

Availability

Page 14: NoSQL & MongoDB

BASE

neutralA C I D

PH

SB EA

Page 15: NoSQL & MongoDB

asically vailable

ventually Consistent

oft-stateS

B

E

A

Page 16: NoSQL & MongoDB

Why No-SQL?

Traditional RDBMS —— CA

Do We really need Transaction?

Horizontal-Scale

Page 17: NoSQL & MongoDB

List Of NoSQL DBs

Wide Column Store

Document Store

Key Value / Tuple Store

Graph Databases

Page 18: NoSQL & MongoDB

mongoDB

Page 19: NoSQL & MongoDB

10gen

established in 2007, @New York

originally aimed to build a Paas architecture

released MongoDB, maintaining it

Page 20: NoSQL & MongoDB

MongoDB Inc.(2013.08)

established in 2007, @New York

originally aimed to build a Paas architecture

released MongoDB, maintaining it

Page 21: NoSQL & MongoDB

MongoDB

document-oriented(BSON) Storage

schema-free

high-performance

build for scale

Page 22: NoSQL & MongoDB

Document

Page 23: NoSQL & MongoDB

Data-Model Design

References

Embedded

Page 24: NoSQL & MongoDB

Reference

Page 25: NoSQL & MongoDB

Embedded

Page 26: NoSQL & MongoDB

which way is better?

No Define answer.

Page 27: NoSQL & MongoDB

A Instance

Page 28: NoSQL & MongoDB

{          "actor_attributes"  :  {                  "name"  :  "Dan  Tao",                  "company"  :  "Google",                  ...                  "email"  :  "[email protected]"          },          "repository"  :  {                  "fork"  :  false,                  "watchers"  :  0,                  "description"  :  "Oh,  nothing,  nothing",                  ...                  "id"  :  13155632,                  "name"  :  "breakneck"          },          "url"  :  "https://github.com/dtao/breakneck/compare/dccee09561...38984e5dce",          "created_at"  :  "2013-­‐09-­‐28T18:00:06-­‐07:00",          "actor"  :  "dtao",          "public"  :  true,          "type"  :  "PushEvent",          "payload"  :  {                  "shas"  :  [                            [                                  ...                          ]                  ],                  "head"  :  "38984e5dce1a21b778d4c26bde493270b4625662",                  "ref"  :  "refs/heads/master",                  "size"  :  1          }  }

Page 29: NoSQL & MongoDB

RDBMS——ERD

Actor Repo

Event

1..n

1..1

1..n

1..1

Page 30: NoSQL & MongoDB

While in mongo…

{  "_id"  :  ObjectId("5287d3e947e36f2280584179")  "actor_attributes"  :  {                  "name"  :  "Dan  Tao",                  "company"  :  "Google",                  ...                  "email"  :  "[email protected]"          }  }

{  "_id"  :  ObjectId("5287d3e947e36f22805844b3")  "actor_attributes"  :  {                  "name"  :  "Dan  Tao",                  "company"  :  "Google",                  ...                  "email"  :  "[email protected]"          }  }

{  "_id"  :  ObjectId("5287d3e947e36f22805844c9")  "actor_attributes"  :  {                  "name"  :  "Dan  Tao",                  "company"  :  "Google",                  ...                  "email"  :  "[email protected]"          }  }

Actor

Page 31: NoSQL & MongoDB

{  "_id"  :  ObjectId("5287d41647e36f2280586033"),  “repository"  :  {                  "fork"  :  false,                              ...                    "name"  :  "breakneck"          },          "actor"  :  "Sam",          …          "payload"  :  {                  "shas"  :  [                            [                                  ...                          ]                  ],                  "ref"  :  "refs/heads/master",                  "size"  :  1          }  }

Event

{  "_id"  :  ObjectId("5287d41647e36f2280586035"),  “repository"  :  {                  "fork"  :  false,                              ...                    "name"  :  "breakneck"          },          "actor"  :  "Tom",          …          "payload"  :  {                  "shas"  :  [                            [                                  ...                          ]                  ],                  "ref"  :  "refs/heads/master",                  "size"  :  1          }  }

{  "_id"  :  ObjectId("5287d41647e36f2280586537"),  “repository"  :  {                  "fork"  :  false,                              ...                    "name"  :  "breakneck"          },          "actor"  :  "Mike",          …          "payload"  :  {                  "shas"  :  [                            [                                  ...                          ]                  ],                  "ref"  :  "refs/heads/master",                  "size"  :  1          }  }

Page 32: NoSQL & MongoDB

Summary

No-SQL => No? No!

Why No-SQL?

CAP & BASE

MongoDB (Inc.)

Schema design

Page 33: NoSQL & MongoDB

How to Choose?

Depending on your needs…

Page 34: NoSQL & MongoDB

Thanks@liushuaikobe

Page 35: NoSQL & MongoDB

Q & A

http://www.girlsgonestrong.com/video-qa/