Introduction To MongoDB
-
Upload
kristina8955 -
Category
Documents
-
view
24 -
download
0
description
Transcript of Introduction To MongoDB
![Page 1: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/1.jpg)
Introduction to
![Page 2: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/2.jpg)
"MongoDB is a scalable, high-performance, open source, schema-free, document-oriented database."
![Page 3: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/3.jpg)
Goal: be the best database for (most) web apps
...not the best DB for everything.
![Page 4: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/4.jpg)
What do Web Apps Want?
Performance
Scalability
Availability
![Page 5: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/5.jpg)
What do developers want?
![Page 6: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/6.jpg)
![Page 7: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/7.jpg)
What else do developers want?
Easier development
Less maintenance (at 3am)
Great support
![Page 8: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/8.jpg)
Goals Easy-to-use
Fast
Always available
Easy to scale
![Page 9: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/9.jpg)
Goals Easy-to-use
Fast
Always available
Easy to scale
![Page 10: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/10.jpg)
5-minute install
Download binaries from
http://www.mongodb.org
and run!
![Page 11: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/11.jpg)
Mongo knows JavaScript
$ ./mongo
MongoDB shell version: 1.3.2
url: test
connecting to: test
type "help" for help
>
![Page 12: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/12.jpg)
Mongo knows JavaScript
$ ./mongo
MongoDB shell version: 1.3.2
url: test
connecting to: test
type "help" for help
> x = 123+1
124
>
![Page 13: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/13.jpg)
![Page 14: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/14.jpg)
mongo.kylebanker.com
![Page 15: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/15.jpg)
Basic Usage
$ ./mongo
MongoDB shell version: 1.3.2
url: test
connecting to: test
type "help" for help
>
![Page 16: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/16.jpg)
Basic Usage
$ ./mongo
MongoDB shell version: 1.3.2
url: test
connecting to: test
type "help" for help
> db
test
>
![Page 17: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/17.jpg)
Database ≈ Database> use foo
switched to db foo
>
![Page 18: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/18.jpg)
Database ≈ Database> use foo
switched to db foo
> db
foo
>
![Page 19: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/19.jpg)
Collection ≈ Table> db.my_collection
foo.my_collection
>
![Page 20: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/20.jpg)
Collection ≈ Table> db.my_collection
foo.my_collection
>
![Page 21: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/21.jpg)
Collection ≈ Table> db.my_collection
foo.my_collection
> db.jzxgtx.find()
>
![Page 22: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/22.jpg)
Collection ≈ Table> db.my_collection
foo.my_collection
> db.jzxgtx.find()
> db.pltzbt.count()
0
>
![Page 23: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/23.jpg)
Document ≈ Row{
"title" : "My first blog post",
"author" : "Fred",
"content" : "Hello, world!",
"comments" : []
}
![Page 24: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/24.jpg)
Documents
Language Document
JavaScript {"foo" : "bar"}
Perl {"foo" => "bar"}
PHP array("foo" => "bar")
Python {"foo" : "bar"}
Ruby {"foo" => "bar"}
Java DBObject obj = new BasicDBObject("foo", "bar");
![Page 25: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/25.jpg)
Documents{
"title" : "My first blog post",
"author" : "Fred",
"content" : "Hello, world!",
"comments" : []
}
![Page 26: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/26.jpg)
Documents> db.posts.insert({
... "title" : "My first blog post",
... "author" : "Fred",
... "content" : "Hello, world!",
... "comments" : [] })
>
![Page 27: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/27.jpg)
Documents> post = db.posts.findOne()
{
"_id" : ObjectId("2fe3e4d892aa73234c910bed"),
"title" : "My first blog post",
"author" : "Fred",
"content" : "Hello, world!",
"comments" : []
}
>
![Page 28: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/28.jpg)
Documents> post = db.posts.findOne()
{
"_id" : ObjectId("2fe3e4d892aa73234c910bed"),
"title" : "My first blog post",
"author" : "Fred",
"content" : "Hello, world!",
"comments" : []
}
>
![Page 29: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/29.jpg)
ObjectIdQ: How do we make a unique ID quickly that is guaranteed to
be unique across multiple servers?
A:
> print(post._id)
2fe3e4d892aa73234c910bed
|------||----||--||----|
ts mac pid inc
Built-in document creation timestamp
![Page 30: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/30.jpg)
A few examples...
![Page 31: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/31.jpg)
Chess
![Page 32: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/32.jpg)
{
"name" : "black king",
"symbol" : "♚",
"pos" : {
"x" : "e",
"y" : 8
}
}
![Page 33: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/33.jpg)
Moving> db.chess.update(
{
"name" : "black king",
"symbol" : "♚",
"pos" : {"x":"e", "y":8}
}
![Page 34: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/34.jpg)
Moving> db.chess.update(
... {"name" : "black king"},
{
"name" : "black king",
"symbol" : "♚",
"pos" : {"x":"e", "y":8}
}
![Page 35: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/35.jpg)
Moving> db.chess.update(
... {"name" : "black king"},
... {"$inc" : {"pos.y" : -1}})
>
{
"name" : "black king",
"symbol" : "♚",
"pos" : {"x":"e", "y":8}
}
![Page 36: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/36.jpg)
Moving> db.chess.update(
... {"name" : "black king"},
... {"$inc" : {"pos.y" : -1}})
>
![Page 37: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/37.jpg)
Moving> db.chess.update(
... {"name" : "black king"},
... {"$inc" : {"pos.y" : -1}})
> db.chess.find({"name" : "black king"})
{
"name" : "black king",
"symbol" : "♚",
"pos" : {"x" : "e", "y" : 7}
}
![Page 38: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/38.jpg)
Adding Information> db.chess.update(
... {"name" : /pawn/},
... {"$set" : {"importance" : 1}})
>
![Page 39: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/39.jpg)
Adding Information> db.chess.update(
... {"name" : /pawn/},
... {"$set" : {"importance" : 1}})
> db.chess.findOne({"symbol" : "♙"})
{
"name" : "white pawn a",
"symbol" : "♙ ",
"pos" : {"x" : "a", "y" : 2},
"importance" : 1
}
![Page 40: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/40.jpg)
Types null
boolean
integer
long
double
string
array
object
date
binary data
object id
regular expression
code
max value
min value
![Page 41: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/41.jpg)
Querying> db.chess.find()
![Page 42: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/42.jpg)
Querying
1
8
a h
![Page 43: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/43.jpg)
Querying> db.chess.find().sort(
... {"pos.y" : -1, "pos.x" : 1})
![Page 44: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/44.jpg)
Querying> db.chess.find(
... {"name" : /white/}).sort(
... {"pos.y" : -1, "pos.x" : 1})
![Page 45: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/45.jpg)
Querying> db.chess.find().sort(
... {"importance" : -1}).limit(1)
![Page 46: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/46.jpg)
Querying> db.chess.find().sort(
... {"importance" : -1}).limit(1).skip(1)
![Page 47: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/47.jpg)
Query Conditions> db.chess.find({"pos.y" : 1})
![Page 48: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/48.jpg)
Query Conditions> db.chess.find({"pos.y" :
... {"$gt" : 2, "$lt" : 7}})
![Page 49: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/49.jpg)
Query Conditions> db.chess.find({"pos.y" :
... {"$gt" : 2, "$lt" : 7},
... "pos.x" :
... {"$ne" : "b"}})
![Page 50: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/50.jpg)
"$gte"
![Page 51: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/51.jpg)
"<null>"
![Page 52: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/52.jpg)
""
![Page 53: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/53.jpg)
'$gte' or "\$gte"
![Page 54: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/54.jpg)
Or define your own!
":gte"
"=gte"
"?gte"
![Page 55: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/55.jpg)
Or define your own!
" gte"
![Page 56: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/56.jpg)
Or define your own!
" gte"
"♕ gte"
![Page 57: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/57.jpg)
Or define your own!
" gte"
"♕ gte"
"xgte"
![Page 58: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/58.jpg)
Other Neat Stuff
![Page 59: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/59.jpg)
Analytics{
"uri" : "/blog",
"pageviews" : 0
}
![Page 60: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/60.jpg)
Analytics - Increment Pageviewspage = db.analytics.findOne({"uri" : "/blog"});
if (page != null) {
page.pageviews++;
db.analytics.save(page);
}
else {
db.analytics.insert({
"uri" : "/blog",
"pageviews" : 1});
}
...that's 1 round trip + 1 update or insert.
![Page 61: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/61.jpg)
Analytics - Upsert
db.analytics.update(
{ "uri" : "/blog" },
{ "$inc" : { "pageviews" => 1 } },
{ "upsert" : true });
...all in one update!
![Page 62: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/62.jpg)
Capped Collections
4 GB, 50 MB, 97 documents, etc.
![Page 63: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/63.jpg)
Capped Collections
4 GB, 50 MB, 97 documents, etc.
![Page 64: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/64.jpg)
Capped Collections
4 GB, 50 MB, 97 documents, etc.
![Page 65: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/65.jpg)
Storing Files - GridFS
Max: 4 MB
![Page 66: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/66.jpg)
Storing Files - GridFS
(More than 4 MB)
![Page 67: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/67.jpg)
Storing Files - GridFS
chunks
JJ J
J
JJ
J
J
J
J_id :files
![Page 68: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/68.jpg)
Storing Files - GridFS
$grid = $db->get_gridfs();
$grid->insert($fh,
{"permissions" => 644,
"comment" => "vacation pics"});
![Page 69: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/69.jpg)
Storing Files - GridFS
$file = $grid->find_one($query);
$file->print($another_fh);
![Page 70: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/70.jpg)
JavaScript Functions> db.eval("function() { return 'hello'; }")
hello
>
![Page 71: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/71.jpg)
JavaScript Functions> db.eval("function() { return 'hello'; }")
hello
>
> func = "function(x) {" +
... "return 'hello '+ x + '!';" +
... "}"
>
![Page 72: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/72.jpg)
JavaScript Functions> db.eval("function() { return 'hello'; }")
hello
>
> func = "function(x) {" +
... "return 'hello '+ x + '!';" +
... "}"
> db.eval(func, ["joe"])
hello, joe!
![Page 73: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/73.jpg)
"Stored Procedures"
> db.system.js.insert({
... "_id" : "x",
... "value" : 3});
>
> db.system.js.insert({
... "_id" : "y",
... "value" : 4});
>
![Page 74: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/74.jpg)
"Stored Procedures"
> db.system.js.insert({
... "_id" : "x",
... "value" : 3});
>
> db.system.js.insert({
... "_id" : "y",
... "value" : 4});
>
> db.eval("return x+y");
7
![Page 75: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/75.jpg)
Goals Easy-to-use
Fast
Always available
Easy to scale
![Page 76: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/76.jpg)
Query Optimizer
CB
A
![Page 77: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/77.jpg)
Query Optimizer
CB
A
Done!
![Page 78: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/78.jpg)
Performance
"Any operation that takes longer than 0 milliseconds is suspect."
- Mongo user on IRC
![Page 79: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/79.jpg)
Performance
Database Average Insert
MongoDB 0.00011
MySQL 0.00083
CouchDB 0.00640
Memcached 0.00279
100,000 inserts (with indexes for MongoDB and MySQL)
![Page 80: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/80.jpg)
Performance
Database Average Query (Indexed)
MongoDB 0.00035
MySQL 0.00772
CouchDB 0.01640
Memcached 0.00015
![Page 81: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/81.jpg)
The Space-Time Continuum
Space
Time
![Page 82: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/82.jpg)
The Space-Time Continuum
Space
Time
![Page 83: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/83.jpg)
Care and Feeding of a Mongod
Server
Laptop
![Page 84: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/84.jpg)
Keeps your databasein memory
Data size
![Page 85: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/85.jpg)
Keeps your databasein memory
Keep indexesin memory
Data size
![Page 86: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/86.jpg)
Keeps your databasein memory
Keep indexesin memory
Keep the portion of the indexes you're using in memory
Data size
![Page 87: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/87.jpg)
Keeps your databasein memory
Keep indexesin memory
Hits the disk andtakes forever.
Data size
Keep the portion of the indexes you're using in memory
![Page 88: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/88.jpg)
Goals Easy-to-use
Fast
Always available
Easy to scale
![Page 89: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/89.jpg)
master
slave slaveslave
![Page 90: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/90.jpg)
master
slave
Replica Pairs
![Page 91: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/91.jpg)
slave
Replica Pairs
![Page 92: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/92.jpg)
master
Replica Pairs
![Page 93: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/93.jpg)
master
slave
Replica Pairs
![Page 94: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/94.jpg)
master
slave
Coming soon... replica sets
slave
slave
![Page 95: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/95.jpg)
Eventual Consistency
![Page 96: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/96.jpg)
Hey Twitter, I'm eating a donut.
Fred
Okay
![Page 97: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/97.jpg)
Hey Twitter, I'm eating a donut.
Fail Whale
1,000,000x
Fred
![Page 98: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/98.jpg)
Hey Twitter, I'm eating a donut.
Fred
Okay
![Page 99: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/99.jpg)
Hey Twitter, I'm eating a donut.
Okay
Fred
Bob
Nothing new
from Fred
![Page 100: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/100.jpg)
Hey Twitter, I'm eating a donut.
Fred
One sec
![Page 101: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/101.jpg)
Bob
Wait a sec, Bob
![Page 102: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/102.jpg)
Bob
I'd rather have Twitter up and know what Fred is doing later.
...eventual consistency works for your customers
![Page 103: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/103.jpg)
Bob
I MUST KNOW WHAT FRED IS DOING RIGHT THIS SECOND!
...you need "real" consistency
![Page 104: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/104.jpg)
Transactions
![Page 105: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/105.jpg)
A Transaction
Insert this.
Okay, got it.
Phew, my data's safe.
![Page 106: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/106.jpg)
A Transaction
![Page 107: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/107.jpg)
A Transaction
![Page 108: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/108.jpg)
Get Paranoid
Insert this.
Okay, got it.
Phew, my data's safe.
![Page 109: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/109.jpg)
Get Paranoid
![Page 110: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/110.jpg)
Get Paranoid
? I have no idea what
you're talking about.
![Page 111: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/111.jpg)
Get Real Paranoid
Write this to disk
All over it!
I know better than
he does, I'll just
let this sit in a
buffer for a while.
![Page 112: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/112.jpg)
Trust No One!
...trust a bunch of ones. Mostly.
![Page 113: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/113.jpg)
Goals Easy-to-use
Fast
Always available
Easy to scale
![Page 114: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/114.jpg)
WARNING!
α
![Page 115: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/115.jpg)
shardshard
shard
shard
![Page 116: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/116.jpg)
![Page 117: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/117.jpg)
I want Bob's comments
![Page 118: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/118.jpg)
Those are stored here.
![Page 119: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/119.jpg)
Comments from Bob?
Here you go.
![Page 120: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/120.jpg)
Server #3, you're
getting overloaded.
Configuration
![Page 121: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/121.jpg)
Server #3, lockdown.
Split the data,
migrate half to the
new shard.
Router, server #3 has
A-M, server #5 has N-Z.
![Page 122: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/122.jpg)
![Page 123: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/123.jpg)
![Page 124: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/124.jpg)
Configuration
Routers
Shards
![Page 125: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/125.jpg)
Scaling
![Page 126: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/126.jpg)
NoSQL LiveMarch 11in Boston
See www.10gen.com/events for details
![Page 127: Introduction To MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051208/5469fbe4b4af9f09638b4b74/html5/thumbnails/127.jpg)
Thank You!
www.mongodb.org
irc.freenode.net#mongodb
http://groups.google.com/group/mongodb-user
@kchodorow