No-SQL & mongoDB
@liushuaikobe
What’s No-SQL?
Strozzi NoSQL

(1998)

RDBMS
operator-stream
paradigm(PIPE)

Carlo Strozzi

a set of shell
routines that access
normal files of the
OS
No-SQL == Not Have SQL
Structured Query Language

No-SQL == Not Have SQL
…departs from the
relational model altogether; it
should therefore have been called
more appropriately 'NoREL'.
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”
No-SQL == non-relational
My regret however isn't about
what the name says, it's about
what it doesn't.

Eric Evans
no:sql(east) conference@ Atlanta
> select fun, profit
> from real_world
> where relational=false;
No-SQL == Not Only SQL
CAP Theorem

(Eric Brewer)

Consistency

Availability

Partition Tolerance
BASE
PH

A C I D

neutral

B A S E
B asically A vailable
S oft-state
Eventually Consistent
Why No-SQL?
Traditional RDBMS —— CA
Do We really need Transaction?
Horizontal-Scale
List Of NoSQL DBs
Wide Column Store
Document Store
Key Value / Tuple Store
Graph Databases
…
mongoDB
10gen
established in 2007, @New York
originally aimed to build a Paas
architecture
released MongoDB, maintaining it
MongoDB Inc.

(2013.08)

established in 2007, @New York
originally aimed to build a Paas
architecture
released MongoDB, maintaining it
MongoDB
document-oriented(BSON) Storage
schema-free
high-performance
build for scale
Document
Data-Model Design

References
Embedded
Reference
Embedded
which way is better?

No Define answer.
A Instance
{	
  
	
  	
  	
  	
  "actor_attributes"	
  :	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  "name"	
  :	
  "Dan	
  Tao",	
  
	
  	
  	
  	
  	
  	
  	
  	
  "company"	
  :	
  "Google",	
  
	
  	
  	
  	
  	
  	
  	
  	
  ...	
  
	
  	
  	
  	
  	
  	
  	
  	
  "email"	
  :	
  "daniel.tao@gmail.com"	
  
	
  	
  	
  	
  },	
  
	
  	
  	
  	
  "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	
  
	
  	
  	
  	
  }	
  
}
RDBMS——ERD
Actor

Repo

1..1

1..1

1..n

1..n

Event
While in mongo…
{	
  
"_id"	
  :	
  ObjectId("5287d3e947e36f2280584179")	
  
"actor_attributes"	
  :	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  "name"	
  :	
  "Dan	
  Tao",	
  
	
  	
  	
  	
  	
  	
  	
  	
  "company"	
  :	
  "Google",	
  
	
  	
  	
  	
  	
  	
  	
  	
  ...	
  
	
  	
  	
  	
  	
  	
  	
  	
  "email"	
  :	
  "daniel@gmail.com"	
  
{	
  
	
  	
  	
  	
  }	
  "_id"	
  :	
  ObjectId("5287d3e947e36f22805844b3")	
  
}
"actor_attributes"	
  :	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  "name"	
  :	
  "Dan	
  Tao",	
  
	
  	
  	
  	
  	
  	
  	
  	
  "company"	
  :	
  "Google",	
  
	
  	
  	
  	
  	
  	
  	
  	
  ...	
  
	
  	
  	
  	
  	
  	
  	
  	
  "email"	
  :	
  "daniel@gmail.com"	
  
{	
  
	
  	
  	
  	
  }	
  
"_id"	
  :	
  ObjectId("5287d3e947e36f22805844c9")	
  
}
"actor_attributes"	
  :	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  "name"	
  :	
  "Dan	
  Tao",	
  
	
  	
  	
  	
  	
  	
  	
  	
  "company"	
  :	
  "Google",	
  
	
  	
  	
  	
  	
  	
  	
  	
  ...	
  
	
  	
  	
  	
  	
  	
  	
  	
  "email"	
  :	
  "daniel@gmail.com"	
  
	
  	
  	
  	
  }	
  
}

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

Event
Summary
No-SQL => No? No!
Why No-SQL?
CAP & BASE
MongoDB (Inc.)
Schema design
How to Choose?

Depending on your needs…
Thanks
@liushuaikobe
Q & A

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

NoSQL & MongoDB

  • 1.
  • 2.
  • 3.
    Strozzi NoSQL (1998) RDBMS operator-stream paradigm(PIPE) Carlo Strozzi aset of shell routines that access normal files of the OS
  • 4.
    No-SQL == NotHave SQL
  • 5.
  • 6.
    …departs from the relationalmodel altogether; it should therefore have been called more appropriately 'NoREL'.
  • 7.
    A meetup@San Francisco ——"opensource, distributed, non relational databases” Organized by Johan Oskarsson(Last.fm) Google's Bigtable & Amazon's Dynamo Eric Evans(then in RackSpace) reintroduced “No-SQL”
  • 8.
  • 9.
    My regret howeverisn't about what the name says, it's about what it doesn't. Eric Evans
  • 10.
  • 11.
    > select fun,profit > from real_world > where relational=false;
  • 12.
    No-SQL == NotOnly SQL
  • 13.
  • 14.
    BASE PH A C ID neutral B A S E
  • 15.
    B asically Available S oft-state Eventually Consistent
  • 16.
    Why No-SQL? Traditional RDBMS—— CA Do We really need Transaction? Horizontal-Scale
  • 17.
    List Of NoSQLDBs Wide Column Store Document Store Key Value / Tuple Store Graph Databases …
  • 18.
  • 19.
    10gen established in 2007,@New York originally aimed to build a Paas architecture released MongoDB, maintaining it
  • 20.
    MongoDB Inc. (2013.08) established in2007, @New York originally aimed to build a Paas architecture released MongoDB, maintaining it
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
    which way isbetter? No Define answer.
  • 27.
  • 28.
    {          "actor_attributes"  :  {                  "name"  :  "Dan  Tao",                  "company"  :  "Google",                  ...                  "email"  :  "daniel.tao@gmail.com"          },          "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          }   }
  • 29.
  • 30.
    While in mongo… {   "_id"  :  ObjectId("5287d3e947e36f2280584179")   "actor_attributes"  :  {                  "name"  :  "Dan  Tao",                  "company"  :  "Google",                  ...                  "email"  :  "daniel@gmail.com"   {          }  "_id"  :  ObjectId("5287d3e947e36f22805844b3")   } "actor_attributes"  :  {                  "name"  :  "Dan  Tao",                  "company"  :  "Google",                  ...                  "email"  :  "daniel@gmail.com"   {          }   "_id"  :  ObjectId("5287d3e947e36f22805844c9")   } "actor_attributes"  :  {                  "name"  :  "Dan  Tao",                  "company"  :  "Google",                  ...                  "email"  :  "daniel@gmail.com"          }   } Actor
  • 31.
    {   "_id"  :  ObjectId("5287d41647e36f2280586033"),   “repository"  :  {                  "fork"  :  false,                              ...                    "name"  :  "breakneck"          },   {          "actor"  :  "Sam",   "_id"  :  ObjectId("5287d41647e36f2280586035"),          …   “repository"  :  {          "payload"  :  {                  "fork"  :  false,                  "shas"  :  [                                ...                          [                      "name"  :  "breakneck"                                ...   {          },                          ]   "_id"  :  ObjectId("5287d41647e36f2280586537"),          "actor"  :  "Tom",                  ],   “repository"  :  {          …                  "ref"  :  "refs/heads/master",                  "fork"  :  false,          "payload"  :  {                  "size"  :  1                              ...                  "shas"  :  [            }                    "name"  :  "breakneck"                          [     }        },                                ...          "actor"  :  "Mike",                          ]                  ],          …          "payload"  :  {                  "ref"  :  "refs/heads/master",                  "shas"  :  [                    "size"  :  1                          [            }                                ...   }                        ]                  ],                  "ref"  :  "refs/heads/master",                  "size"  :  1          }   } Event
  • 32.
    Summary No-SQL => No?No! Why No-SQL? CAP & BASE MongoDB (Inc.) Schema design
  • 33.
    How to Choose? Dependingon your needs…
  • 34.
  • 35.