• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Introduction to MongoDB - Austin Code Camp 2011
 

Introduction to MongoDB - Austin Code Camp 2011

on

  • 1,912 views

Video at: http://www.chrisedwards.dreamhosters.com/blog/2011/09/10/video-introduction-to-mongodb-austin-code-camp-2011/ ...

Video at: http://www.chrisedwards.dreamhosters.com/blog/2011/09/10/video-introduction-to-mongodb-austin-code-camp-2011/

A high level overview of MongoDB targeting developers that have never heard of or used MongoDB. We look at its features and capabilities, how to install and configure it, and how to use it. We cover querying, indexing, sharding and replication. I try hard to state everything in terms of SQL Server to give the audience a context to help understand the new NoSql concepts in MongoDB. I also use animations to help clarify the more difficult concepts of sharding and replication.

Statistics

Views

Total Views
1,912
Views on SlideShare
1,843
Embed Views
69

Actions

Likes
3
Downloads
87
Comments
0

6 Embeds 69

http://octopresszhangyu.heroku.com 35
http://192.168.136.131:4000 24
http://octopresszhangyu.herokuapp.com 6
http://cache.baidu.com 2
http://www.codemav.com 1
http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • This is a test note\n
  • \n
  • Collection\n - Documents can be anything\n - Advantageous if they are similar\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • Prejoined relationship\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Introduction to MongoDB - Austin Code Camp 2011 Introduction to MongoDB - Austin Code Camp 2011 Presentation Transcript

  • +)1*3$&4(56&4#70&89::& !"#$%&()&*(&+,,&-).&/0($1(.12& h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m
  • Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - C O D E - C A M P - 2 0 1 1 Chris Edwards h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m
  • MongoDB h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m
  • About Me Chris Edwards Architect at BancVue Ltd. Email: ChrisEdwards357@gmail.com Blog: http://chrisedwards.dreamhosters.com Twitter: @cedwards Github: http://github.com/chrisedwards (Sample code for this talk is posted) h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • What is No-SQL? h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • What is No-SQL? “Next Generation Databases mostly addressing some of the points: being non-relational, distributed, open-source and horizontal scalable. ... schema-free, easy replication support, simple API, eventually consistent ...” - nosql-database.org h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • What is No-SQL? “Next Generation Databases mostly addressing some of the points: being non-relational, distributed, open-source and horizontal scalable. ... schema-free, easy replication support, simple API, eventually consistent ...” - nosql-database.org • Non-Relational • Schema-Free • Distributed • Replication Support • Open-Source • Simple API • Horizontally Scalable • Eventually Consistent h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • What is No-SQL? It’s about using the right tool for the job. • Not all systems have the same data needs. • Sql is not the only option, nor is it always the best one. • Consider all options carefully and choose wisely. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • What is No-SQL? It’s about using the right tool for the job. • Not all systems have the same data needs. • Sql is not the only option, nor is it always the best one. • Consider all options carefully and choose wisely. Not Only SQL h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • What is No-SQL? It’s about using the right tool for the job. • Not all systems have the same data needs. • Sql is not the only option, nor is it always the best one. • Consider all options carefully and choose wisely. Not Only SQL It’s not about flaming SQL. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • What is No-SQL? It’s about using the right tool for the job. • Not all systems have the same data needs. • Sql is not the only option, nor is it always the best one. • Consider all options carefully and choose wisely. Not Only SQL It’s not about flaming SQL. Its about opening our minds to new technologies. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • What is MongoDB? • Document-oriented database - Uses JSON (BSON actually) • Schema-free • Performant - Written in C++ - Full index support - No transactions (has atomic operations) “Mongo only pawn in game of life” - Memory-mapped files (delayed writes) • Replication & High Availability • Auto Sharding • Commercially supported (10gen) - Lots of documentation h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • Other Features of MongoDB • Document-based queries - Flexible document queries expressed in JSON/Javascript. • Map Reduce - Flexible aggregation and data processing. - Queries run in parallel on all shards. • GridFS - Store files of any size easily. • Geospatial Indexing - Find object based on location. (i.e. find closest n items to x) • Many Production Deployments h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • Other Features of MongoDB • Supported on Multiple Platforms - OSX - Linux - Solaris - Windows - FreeBSD h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Concepts Document - Analogous to a row in RDBMS - Represented as JSON (BSON) - Hierarchical - Can reference other documents h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Concepts Collection - Analogous to a table in RDBMS - Collection of documents - Documents can be anything - Advantageous if they are similar h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Concepts Embedding {
_id:
objectid(4b980a6dea2c3f4579da141e), - Analogous to a foreign key 

user_id:
objectid(4b980a6dea2c3f4579a4f54), 

state:
in_cart, - Think “pre-joined relationship”. 

line_items:
[ - Clearer conceptual model. 



{
sku:
jc‐432, 





name:
John
Coltrane:
A
Love
Supreme, - DDD Aggregate Root 





retail_price:
1099 - Can be 



}, - Sub Objects 



{
sku:
ly‐211, 





name:
Larry
Young:
Unity, - Collections 





retail_price:
1199 



} 

], 

shipping_address:
{ 



street:
3333
Greene
Ave., 



city:
Brooklyn, 



state:
NY, 



zip:
11216 

}, 

subtotal:
2199 } h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Concepts Embedding {
_id:
objectid(4b980a6dea2c3f4579da141e), - Analogous to a foreign key 

user_id:
objectid(4b980a6dea2c3f4579a4f54), 

state:
in_cart, - Think “pre-joined relationship” 

line_items:
[ - Clearer conceptual model. 



{
sku:
jc‐432, 





name:
John
Coltrane:
A
Love
Supreme, - DDD Aggregate Root 





retail_price:
1099 - Can be 



}, - Sub Objects 



{
sku:
ly‐211, 





name:
Larry
Young:
Unity, - Collections 





retail_price:
1199 



} 

], 

shipping_address:
{ References 



street:
3333
Greene
Ave., 



city:
Brooklyn, 



state:
NY, - Analogous to a foreign key 



zip:
11216 

}, - Think “relationship” 

subtotal:
2199 } h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Operations Querying All the following queries will find the document. {
_id:
objectid(4b980a6dea2c3f4579da141e), 

user_id:
objectid(4b980a6dea2c3f4579a4f54), 

state:
in_cart, 

line_items:
[ 



{
sku:
jc‐432, 





name:
John
Coltrane:
A
Love
Supreme, 





retail_price:
1099 



}, 



{
sku:
ly‐211, 





name:
Larry
Young:
Unity, 





retail_price:
1199 



} 

], 

shipping_address:
{ 



street:
3333
Greene
Ave., 



city:
Brooklyn, 



state:
NY, 



zip:
11216 

}, 

subtotal:
2199 } h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Operations Querying All the following queries will find the document. By property value db.orders.find(
{
"state":
"in_cart"
}
); {
_id:
objectid(4b980a6dea2c3f4579da141e), 

user_id:
objectid(4b980a6dea2c3f4579a4f54), 

state:
in_cart, 

line_items:
[ 



{
sku:
jc‐432, 





name:
John
Coltrane:
A
Love
Supreme, 





retail_price:
1099 



}, 



{
sku:
ly‐211, 





name:
Larry
Young:
Unity, 





retail_price:
1199 



} 

], 

shipping_address:
{ 



street:
3333
Greene
Ave., 



city:
Brooklyn, 



state:
NY, 



zip:
11216 

}, 

subtotal:
2199 } h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Operations Querying All the following queries will find the document. By property value db.orders.find(
{
"state":
"in_cart"
}
); {
_id:
objectid(4b980a6dea2c3f4579da141e), By embedded object property value 

user_id:
objectid(4b980a6dea2c3f4579a4f54), 

state:
in_cart, db.orders.find(
{
"shipping_address.state":
"NY"
}
); 

line_items:
[ 



{
sku:
jc‐432, 





name:
John
Coltrane:
A
Love
Supreme, 





retail_price:
1099 



}, 



{
sku:
ly‐211, 





name:
Larry
Young:
Unity, 





retail_price:
1199 



} 

], 

shipping_address:
{ 



street:
3333
Greene
Ave., 



city:
Brooklyn, 



state:
NY, 



zip:
11216 

}, 

subtotal:
2199 } h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Operations Querying All the following queries will find the document. By property value db.orders.find(
{
"state":
"in_cart"
}
); {
_id:
objectid(4b980a6dea2c3f4579da141e), By embedded object property value 

user_id:
objectid(4b980a6dea2c3f4579a4f54), 

state:
in_cart, db.orders.find(
{
"shipping_address.state":
"NY"
}
); 

line_items:
[ 



{
sku:
jc‐432, 





name:
John
Coltrane:
A
Love
Supreme, With comparison operators 





retail_price:
1099 



}, db.orders.find(
{
"subtotal":
{
$gt:
2000
}
}
); 



{
sku:
ly‐211, 





name:
Larry
Young:
Unity, 





retail_price:
1199 



} 

], 

shipping_address:
{ 



street:
3333
Greene
Ave., 



city:
Brooklyn, 



state:
NY, 



zip:
11216 

}, 

subtotal:
2199 } h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Operations Querying All the following queries will find the document. By property value db.orders.find(
{
"state":
"in_cart"
}
); {
_id:
objectid(4b980a6dea2c3f4579da141e), By embedded object property value 

user_id:
objectid(4b980a6dea2c3f4579a4f54), 

state:
in_cart, db.orders.find(
{
"shipping_address.state":
"NY"
}
); 

line_items:
[ 



{
sku:
jc‐432, 





name:
John
Coltrane:
A
Love
Supreme, With comparison operators 





retail_price:
1099 



}, db.orders.find(
{
"subtotal":
{
$gt:
2000
}
}
); 



{
sku:
ly‐211, 





name:
Larry
Young:
Unity, 





retail_price:
1199 



} Values in collections (implicit “in”) 

], db.orders.find(
{
"line_items.sku":
"ly‐211"
}
); 

shipping_address:
{ 



street:
3333
Greene
Ave., 



city:
Brooklyn, 



state:
NY, 



zip:
11216 

}, 

subtotal:
2199 } h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Operations Indexing {
_id:
objectid(4b980a6dea2c3f4579da141e), 

user_id:
objectid(4b980a6dea2c3f4579a4f54), 

state:
in_cart, 

line_items:
[ 



{
sku:
jc‐432, 





name:
John
Coltrane:
A
Love
Supreme, 





retail_price:
1099 



}, 



{
sku:
ly‐211, 





name:
Larry
Young:
Unity, 





retail_price:
1199 



} 

], 

shipping_address:
{ 



street:
3333
Greene
Ave., 



city:
Brooklyn, 



state:
NY, 



zip:
11216 

}, 

subtotal:
2199 } h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Operations Indexing On property value db.orders.ensureIndex(
{
"state":
1
}
); {
_id:
objectid(4b980a6dea2c3f4579da141e), 

user_id:
objectid(4b980a6dea2c3f4579a4f54), 

state:
in_cart, 

line_items:
[ 



{
sku:
jc‐432, 





name:
John
Coltrane:
A
Love
Supreme, 





retail_price:
1099 



}, 



{
sku:
ly‐211, 





name:
Larry
Young:
Unity, 





retail_price:
1199 



} 

], 

shipping_address:
{ 



street:
3333
Greene
Ave., 



city:
Brooklyn, 



state:
NY, 



zip:
11216 

}, 

subtotal:
2199 } h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Operations Indexing On property value db.orders.ensureIndex(
{
"state":
1
}
); On embedded object property {
_id:
objectid(4b980a6dea2c3f4579da141e), db.orders.ensureIndex(
{
"shipping_address.state":
1
}
); 

user_id:
objectid(4b980a6dea2c3f4579a4f54), 

state:
in_cart, 

line_items:
[ 



{
sku:
jc‐432, 





name:
John
Coltrane:
A
Love
Supreme, 





retail_price:
1099 



}, 



{
sku:
ly‐211, 





name:
Larry
Young:
Unity, 





retail_price:
1199 



} 

], 

shipping_address:
{ 



street:
3333
Greene
Ave., 



city:
Brooklyn, 



state:
NY, 



zip:
11216 

}, 

subtotal:
2199 } h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Operations Indexing On property value db.orders.ensureIndex(
{
"state":
1
}
); On embedded object property {
_id:
objectid(4b980a6dea2c3f4579da141e), db.orders.ensureIndex(
{
"shipping_address.state":
1
}
); 

user_id:
objectid(4b980a6dea2c3f4579a4f54), 

state:
in_cart, 

line_items:
[ On embedded collections 



{
sku:
jc‐432, 





name:
John
Coltrane:
A
Love
Supreme, db.orders.ensureIndex(
{
"line_items.sku":
1
}
); 





retail_price:
1099 



}, 



{
sku:
ly‐211, 





name:
Larry
Young:
Unity, 





retail_price:
1199 



} 

], 

shipping_address:
{ 



street:
3333
Greene
Ave., 



city:
Brooklyn, 



state:
NY, 



zip:
11216 

}, 

subtotal:
2199 } h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Operations Indexing On property value db.orders.ensureIndex(
{
"state":
1
}
); On embedded object property {
_id:
objectid(4b980a6dea2c3f4579da141e), db.orders.ensureIndex(
{
"shipping_address.state":
1
}
); 

user_id:
objectid(4b980a6dea2c3f4579a4f54), 

state:
in_cart, 

line_items:
[ On embedded collections 



{
sku:
jc‐432, 





name:
John
Coltrane:
A
Love
Supreme, db.orders.ensureIndex(
{
"line_items.sku":
1
}
); 





retail_price:
1099 



}, 



{
sku:
ly‐211, On multiple keys 





name:
Larry
Young:
Unity, 





retail_price:
1199 db.orders.ensureIndex(
{
"shipping_address.state":
1, 



} 

], 
























"subtotal":
‐1
}
); 

shipping_address:
{ 



street:
3333
Greene
Ave., 



city:
Brooklyn, 



state:
NY, 



zip:
11216 

}, 

subtotal:
2199 } h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Operations Inserting db.orders.save(
{ 



user_name:
Bob
Smith, 



state:
in_cart, 



shipping_address:
{ 





street:
1234
Morgan
Ave., 





city:
Austin, 





state:
TX, 





zip:
78660 



}, 



subtotal:
0 

}
); h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Operations Updating Using Query/Modify/Save var
order
=
db.orders.find(
{
user_name:
Bob
Smith
}
); order.state
=
in_cart; order.line_items.push(
{
sku:
md‐12, 
























price:
2500, 
























title:
Basketball
}
); order.subtotal
=
order.subtotal
+
2500; db.orders.save(
order
); h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Operations Updating Using Query/Modify/Save var
order
=
db.orders.find(
{
user_name:
Bob
Smith
}
); order.state
=
in_cart; order.line_items.push(
{
sku:
md‐12, 
























price:
2500, 
























title:
Basketball
}
); order.subtotal
=
order.subtotal
+
2500; db.orders.save(
order
); • Requires each object to be loaded in memory. • Requires multiple hits to the database. • Very inefficient. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Operations Updating Using Atomic Updates db.orders.update(
{
_id:
order_id
}, 



{

$set:
{
state:
in_cart
}, 





$push:
{
line_items:
{
sku:
md‐12, 






























price:
2500, 






























title:
Basketball
} 












}, 






$inc:
{
subtotal:
2500
} 



}
); h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Basic Operations Updating Using Atomic Updates db.orders.update(
{
_id:
order_id
}, 



{

$set:
{
state:
in_cart
}, 





$push:
{
line_items:
{
sku:
md‐12, 






























price:
2500, 






























title:
Basketball
} 












}, 






$inc:
{
subtotal:
2500
} 



}
); • Analogous to transactions. • Requires only one trip to the database. • Operations are atomic. • Can perform multiple operations at once. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB System Components h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB System Components mongod.exe The database server h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB System Components mongod.exe mongo.exe The database server The interactive shell h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB System Components mongod.exe mongo.exe The database server The interactive shell mongos.exe The sharding router h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • Installing MongoDB 1. Download MongoDB. www.mongodb.com/downloads 2. Extract it. 3. Create the data folder. usually /data/db -or- C:datadb 4. Run mongod.exe h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • Installing MongoDB 1. Download MongoDB. www.mongodb.com/downloads 2. Extract it. 3. Create the data folder. usually /data/db -or- C:datadb 4. Run mongod.exe That’s it! h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • Accessing MongoDB via the Shell • Inserting a document into a collection. • Querying a collection. • Modifying a document. • Deleting a document. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • Accessing MongoDB via the Shell • Inserting a document into a collection. • Querying a collection. • Modifying a document. • Deleting a document. Lets do it! h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • Accessing MongoDB via REST • To enable basic REST interface, use --rest command line. - mongod.exe --rest • REST interface uses port +1000. - http://127.0.0.1:28017/database/collection/ - http://127.0.0.1:28017/database/collection/?filter&Field=Value • Full REST support is provided by the Sleepy.Mongoose lib. - http://github.com/kchodorow/sleepy.mongoose h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Replica Sets - Full Failover support - Supports more than 2 servers in a replica cluster - Data center and rack aware - Can have passive set members (slaves) that are never primary h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node A Primary Node B Node C Secondary Secondary h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication 1∆ Node A Primary Node B Node C Secondary Secondary h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node A Primary 1∆ Node B Node C Secondary Secondary h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node A Primary 1∆ Node B Node C Secondary Secondary 1∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node A Primary 1∆ Node B Node C Secondary Secondary 1∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication 2∆ Node A Primary 1∆ Node B Node C Secondary Secondary 1∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node A Primary 1∆ 2∆ Node B Node C Secondary Secondary 1∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node A Primary 1∆ 2∆ Node B Node C Secondary Secondary 1∆ 2∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node A Primary 1∆ 2∆ Node B Node C Secondary Secondary 1∆ 2∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication 3∆ Node A Primary 1∆ 2∆ Node B Node C Secondary Secondary 1∆ 2∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node A Primary 1∆ 2∆ 3∆ Node B Node C Secondary Secondary 1∆ 2∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication NodeiA e n O ffl Primary 1∆ 2∆ 3∆ Node B Node C Secondary Secondary 1∆ 2∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication NodeiA e n O ffl Primary 1∆ 2∆ 3∆ Node B Node C Secondary Secondary 1∆ 2∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication READ NodeiA e n ONLY O ffl Primary 1∆ 2∆ 3∆ Node B Node C Secondary Secondary 1∆ 2∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication READ NodeiA e n ONLY O ffl Primary 1∆ 2∆ 3∆ Node B FIGHT! Node C Secondary Secondary 1∆ 2∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication READ NodeiA e n ONLY O ffl Primary 1∆ 2∆ 3∆ Node B Vote Node C Secondary Secondary 1∆ 2∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication READ NodeiA e n ONLY O ffl Primary 1∆ 2∆ 3∆ Node B ME! Node B Node C Secondary Secondary 1∆ 2∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication READ NodeiA e n ONLY O ffl Primary 1∆ 2∆ 3∆ Node B Node C Secondary Secondary 1∆ 2∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication READ ONLY Node B Secondary 1∆ 2∆ NodeiA e n Node C O ffl Primary Secondary 1∆ 2∆ 3∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication READ ONLY Node B Secondary 1∆ 2∆ NodeiA e n Node C O ffl Primary Secondary 1∆ 2∆ 3∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ NodeiA e n Node C O ffl Primary Secondary 1∆ 2∆ 3∆ 1∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ NodeiA e n Node C O ffl Primary Secondary 1∆ 2∆ 3∆ 1∆ 2∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ NodeiA e n Node C O ffl Primary Secondary 1∆ 2∆ 3∆ 1∆ 2∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication 4∆ Node B Primary 1∆ 2∆ NodeiA e n Node C O ffl Primary Secondary 1∆ 2∆ 3∆ 1∆ 2∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ 4∆ NodeiA e n Node C O ffl Primary Secondary 1∆ 2∆ 3∆ 1∆ 2∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ 4∆ NodeiA e n Node C O ffl Primary Secondary 1∆ 2∆ 3∆ 1∆ 2∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ 4∆ NodeiA e n Node C O ffl Primary Secondary 1∆ 2∆ 3∆ 1∆ 2∆ 4∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ 4∆ NodeiA e n Node C O ffl Primary Secondary 1∆ 2∆ 3∆ 1∆ 2∆ 4∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ 4∆ Node A Node C Primary Secondary 1∆ 2∆ 3∆ 1∆ 2∆ 4∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ 4∆ Node A Node C Recovering... Secondary 1∆ 2∆ 3∆ 1∆ 2∆ 4∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ 4∆ Node A Node C Recovering... Secondary 1∆ 2∆ 3∆ 1∆ 2∆ 4∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ 4∆ Node A Node C Recovering... Secondary 1∆ 2∆ 3∆ 1∆ 2∆ 4∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ 4∆ Log Node A Node C Recovering... Secondary 1∆ 2∆ 3∆ 1∆ 2∆ 4∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ 4∆ Log Node A Node C Recovering... Secondary 1∆ 2∆ 3∆ 1∆ 2∆ 4∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ 4∆ Node A Node C Recovering... Secondary 1∆ 2∆ 3∆ 1∆ 2∆ 4∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ 4∆ Node A Node C Recovering... Secondary 1∆ 2∆ 1∆ 2∆ 4∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ 4∆ Node A Node C Recovering... Secondary 1∆ 2∆ 1∆ 2∆ 4∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ 4∆ Node A Node C Recovering... Secondary 1∆ 2∆ 4∆ 1∆ 2∆ 4∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Node B Primary 1∆ 2∆ 4∆ Node A Node C Secondary Secondary 1∆ 2∆ 4∆ 1∆ 2∆ 4∆ h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Replication Demo h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding What is Sharding? h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Solo, Han Zappa, Frank Dent, Arthur Graham, Bill Karras, Alex Falken, Stephen h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Solo, Han Zappa, Frank Dent, Arthur Graham, Bill Karras, Alex Falken, Stephen h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Solo, Han Zappa, Frank Dent, Arthur Graham, Bill Karras, Alex Falken, Stephen h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Falken, Stephen? Solo, Han Zappa, Frank Dent, Arthur Graham, Bill Karras, Alex Falken, Stephen h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Falken, Stephen? 1 2 3 Solo, Han Zappa, Frank Dent, Arthur Graham, Bill Karras, Alex Falken, Stephen h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding 1 2 3 Solo, Han Zappa, Frank Dent, Arthur Graham, Bill Karras, Alex Falken, Stephen h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding 1 2 3 Solo, Han Zappa, Frank Dent, Arthur Graham, Bill Karras, Alex Falken, Stephen h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Falken, Stephen 1 2 3 Solo, Han Zappa, Frank Dent, Arthur Graham, Bill Karras, Alex Falken, Stephen h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding 1 2 3 Solo, Han Zappa, Frank Dent, Arthur Graham, Bill Karras, Alex Falken, Stephen h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding 1 2 3 Dent, Arthur Graham, Bill Solo, Han Falken, Stephen Karras, Alex Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding 1 A-F 2 G-K 3 L-Z Dent, Arthur Graham, Bill Solo, Han Falken, Stephen Karras, Alex Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding 1 A-F 2 G-K 3 L-Z 1 2 3 Dent, Arthur Graham, Bill Solo, Han Falken, Stephen Karras, Alex Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding 1 A-F 2 G-K 3 L-Z 1 2 3 Dent, Arthur Graham, Bill Solo, Han Falken, Stephen Karras, Alex Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Solo, Han? 1 A-F 2 G-K 3 L-Z 1 2 3 Dent, Arthur Graham, Bill Solo, Han Falken, Stephen Karras, Alex Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding 1 A-F 2 G-K 3 L-Z Solo, Han 1 2 3 Dent, Arthur Graham, Bill Solo, Han Falken, Stephen Karras, Alex Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding 1 A-F 2 G-K 3 L-Z 1 2 3 Dent, Arthur Graham, Bill Solo, Han Falken, Stephen Karras, Alex Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding 1 A-F 2 G-K 3 L-Z Shard 1 Shard 2 Shard 3 Dent, Arthur Graham, Bill Solo, Han Falken, Stephen Karras, Alex Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding 1 A-F 2 G-K 3 L-Z Shard Key Shard 1 Shard 2 Shard 3 Dent, Arthur Graham, Bill Solo, Han Falken, Stephen Karras, Alex Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding 1 A-F 2 G-K 3 L-Z Shard 1 Shard 2 Shard 3 Dent, Arthur Graham, Bill Solo, Han Falken, Stephen Karras, Alex Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding 1 A-F 2 G-K 3 L-Z Shard 1 Shard 2 Shard 3 Dent, Arthur Graham, Bill Solo, Han Falken, Stephen Karras, Alex Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Config 1 A-F 2 G-K 3 L-Z Shard 1 Shard 2 Shard 3 Dent, Arthur Graham, Bill Solo, Han Falken, Stephen Karras, Alex Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Config 1 A-F 2 G-K 3 L-Z Shard 1 Shard 2 Shard 3 Dent, Arthur Graham, Bill Solo, Han Falken, Stephen Karras, Alex Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Config 1 A-F 2 G-K 3 L-Z Shard 1 Shard 2 Shard 3 Dent, Arthur Graham, Bill Solo, Han Falken, Stephen Karras, Alex Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Config 1 A-F 2 G-K 3 L-Z Shard 1 Shard 2 Shard 3 Dent, Arthur Graham, Bill Solo, Han Falken, Stephen Karras, Alex Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Config 1 A-F Shard 2 G-K Router 3 L-Z Shard 1 Shard 2 Shard 3 Dent, Arthur Graham, Bill Solo, Han Falken, Stephen Karras, Alex Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Auto-Balancing h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Architecture Shard 1 Chunk 1 (A-Z) Dent, Arthur Falken, Stephen Graham, Bill Karras, Alex Solo, Han Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Architecture Shard 1 Shard 2 Chunk 1 (A-Z) Dent, Arthur Falken, Stephen Graham, Bill Karras, Alex Solo, Han Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Architecture Shard 1 Shard 2 Chunk 1 (A-Z) Dent, Arthur Falken, Stephen Graham, Bill Karras, Alex Solo, Han Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Architecture Shard 1 Shard 2 Chunk 1 (A-Z) Dent, Arthur Falken, Stephen Graham, BillSplit Karras, Alex Solo, Han Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Architecture Shard 1 Shard 2 Chunk 1 (A-H) Dent, Arthur Falken, Stephen Graham,2BillSplit Chunk (K-Z) Karras, Alex Solo, Han Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Architecture Shard 1 Shard 2 Chunk 1 (A-H) Dent, Arthur Falken, Stephen Graham, Bill Chunk 2 (K-Z) Karras, Alex Solo, Han Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Architecture Shard 1 Shard 2 Chunk 1 (A-H) Dent, Arthur Falken, Stephen Graham, Bill Chunk 2 (K-Z) Karras, Alex Solo, Han Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Architecture Shard 1 Shard 2 Chunk 1 (A-H) Dent, Arthur Falken, Stephen Graham, Bill ra te Chunk 2 (K-Z) Mig Karras, Alex Solo, Han Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Architecture Shard 1 Shard 2 Chunk 1 (A-H) Chunk 2 (K-Z) Dent, Arthur Karras, Alex Falken, Stephen Solo, Han Graham, Bill Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Architecture Shard 1 Shard 2 Chunk 1 (A-H) Chunk 2 (K-Z) Dent, Arthur Karras, Alex Falken, Stephen Solo, Han Graham, Bill Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Architecture Shard 1 Shard 2 Chunk 1 (A-H) Chunk 2 (K-Z) Dent, Arthur Karras, Alex Falken, Stephen Solo, Han Graham, Bill Zappa, Frank h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-ShardingArchitecting a Sharded System h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Shard h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Shard h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Node A Primary Each Shard is a Node B Replica Node C Secondary Set Secondary h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Node A Primary Each Shard is a Node B Replica Node C Secondary Set Secondary h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Node A Primary Shard Node B Node C Secondary Secondary h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Node A Primary Shard Node B Node C Secondary Secondary h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Node A Primary Shard Node B Node C Secondary Secondary h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Node A Node A Node A Node A Primary Primary Primary Primary Shard Shard Shard Shard Node B Node C Node B Node C Node B Node C Node B Node C Secondary Secondary Secondary Secondary Secondary Secondary Secondary Secondary h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Node A Node A Node A Node A Primary Primary Primary Primary Shard Shard Shard Shard Node B Node C Node B Node C Node B Node C Node B Node C Secondary Secondary Secondary Secondary Secondary Secondary Secondary Secondary Config Server h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Node A Node A Node A Node A Primary Primary Primary Primary Shard Shard Shard Shard Node B Node C Node B Node C Node B Node C Node B Node C Secondary Secondary Secondary Secondary Secondary Secondary Secondary Secondary Config Server Config Server Config Server h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Node A Node A Node A Node A Primary Primary Primary Primary Shard Shard Shard Shard Node B Node C Node B Node C Node B Node C Node B Node C Secondary Secondary Secondary Secondary Secondary Secondary Secondary Secondary Config Server Shard Config Server Router Config Server h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Node A Node A Node A Node A Primary Primary Primary Primary Shard Shard Shard Shard Node B Node C Node B Node C Node B Node C Node B Node C Secondary Secondary Secondary Secondary Secondary Secondary Secondary Secondary Config Server Shard Config Server Router Config Server Application h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Logical Architecture Node A Node A Node A Node A Primary Primary Primary Primary Shard Shard Shard Shard Node B Node C Node B Node C Node B Node C Node B Node C Secondary Secondary Secondary Secondary Secondary Secondary Secondary Secondary Config Server Shard Config Server Router Config Server Application h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Physical Architecture Node A Node A Node A Node A Primary Primary Primary Primary Shard Shard Shard Shard Node B Node C Node B Node C Node B Node C Node B Node C Secondary Secondary Secondary Secondary Secondary Secondary Secondary Secondary Config Server Shard Config Server Router Config Server Application h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Node A Node A Node A Node A Primary Primary Primary Primary Shard Shard Shard Shard Node B Node C Node B Node C Node B Node C Node B Node C Secondary Secondary Secondary Secondary Secondary Secondary Secondary Secondary Config Server Shard Config Server Router Config Server Application h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Node A Node A Node A Node A Primary Primary Primary Primary Shard Shard Shard Shard Node B Node C Node B Node C Node B Node C Node B Node C Secondary Secondary Secondary Secondary Secondary Secondary Secondary Secondary Config Server Config Server Application Server Shard Router Config Server Application h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding Node A Node A Node A Node A Primary Primary Primary Primary Shard Shard Shard Shard Node B Node C Node B Node C Node B Node C Node B Node C Secondary Secondary Secondary Secondary Secondary Secondary Secondary Secondary Config Server Application Server Application Server Config Server Shard Shard Router Router Config Server Application Application h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-ShardingServer 1 Node A Primary Node A Node A Node A Primary Primary Primary Shard Node B Node C Shard Shard Shard Secondary Secondary Node B Node C Node B Node C Node B Node C Secondary Secondary Secondary Secondary Secondary Secondary Config Server Application Server Application Server Config Server Shard Shard Router Router Config Server Application Application h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-ShardingServer 1 Server 2 Node A Node A Primary Primary Node A Node A Primary Primary Shard Shard Node B Node C Node B Node C Shard Shard Secondary Secondary Secondary Secondary Node B Node C Node B Node C Secondary Secondary Secondary Secondary Config Server Config Server Application Server Application Server Shard Shard Router Router Config Server Application Application h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-ShardingServer 1 Server 2 Server 3 Node A Node A Node A Primary Primary Primary Node A Primary Shard Shard Shard Node B Node C Node B Node C Node B Node C Shard Secondary Secondary Secondary Secondary Secondary Secondary Node B Node C Secondary Secondary Config Server Config Server Config Server Application Server Application Server Shard Shard Router Router Application Application h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-ShardingServer 1 Server 2 Server 3 Server 4 Node A Node A Node A Node A Primary Primary Primary Primary Shard Shard Shard Shard Node B Node C Node B Node C Node B Node C Node B Node C Secondary Secondary Secondary Secondary Secondary Secondary Secondary Secondary Config Server Config Server Config Server Application Server Application Server Shard Shard Router Router Application Application h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Features h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Features • Based on a defined shard key. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Features • Based on a defined shard key. • Auto-balances as shard servers are added or removed. - Can go from single master to sharded system with zero downtime. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Features • Based on a defined shard key. • Auto-balances as shard servers are added or removed. - Can go from single master to sharded system with zero downtime. • Failover handled through replica sets. (each shard replicated) h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Features • Based on a defined shard key. • Auto-balances as shard servers are added or removed. - Can go from single master to sharded system with zero downtime. • Failover handled through replica sets. (each shard replicated) • Map Reduce queries are run in parallel across shards. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Architecture • Shard Servers - Instance of mongod.exe --shardsvr - Optionally configured with a replication set for failover. • Config Servers - Instance of mongod.exe --configsvr - Usually a group of 3. System is up so long as 1 config server is running. • Shard Routers - Instance of mongos.exe --configdb <config server>:<config port> - Acts like mongod.exe to clients. - Can be on the same box as a shard server. - Can run on appserver to reduce traffic. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Auto-Sharding: Configuration Startup Servers • Startup Shard Servers - mongod.exe --shardsvr • Startup Config Servers - mongod.exe --configsvr • Startup Shard Routers - mongos.exe --configdb <config server>:<config port> Configure Cluster • Add Shards to the Cluster - Execute the following command for each shard using either the driver or shell. - db.runcommand( { addshard : “<shard server>:<shard server port>” } ); • Enable Sharding on the Databases to Shard - db.runcommand( { enablesharding : “<dbname>” } ); • Specify Collections to Shard - db.runcommand( { shardCollection : “<collection>”, key : <key pattern> } ); h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1
  • Introduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1 ? h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m
  • Introduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1 ? h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m
  • About Me Chris Edwards Senior Developer at BancVue Ltd. Email: ChrisEdwards357@gmail.com Blog: http://chrisedwards.dreamhosters.com Twitter: @cedwards Github: http://github.com/chrisedwards (Sample code for this talk is posted) h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o mIntroduction to MongoDB A No-SQL Persistence AlternativeA U S T I N - C O D E - C A M P - 2 0 1 1