Introduction to MongoDB
-
Upload
mike-dirolf -
Category
Technology
-
view
17.047 -
download
1
description
Transcript of Introduction to MongoDB
![Page 1: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/1.jpg)
open-‐source, high-‐performance, document-‐oriented database
![Page 2: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/2.jpg)
RDBMS(Oracle, MySQL)
New Gen. OLAP(vertica, aster, greenplum)
Non-relationalOperational Stores
(“NoSQL”)
![Page 3: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/3.jpg)
non-‐relational, next-‐generation operational datastores and databases
NoSQL Really Means:
![Page 4: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/4.jpg)
Horizontally ScalableArchitectures
no joinsno complex transactions+
![Page 5: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/5.jpg)
New Data Models
no joinsno complex transactions+
![Page 6: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/6.jpg)
New Data Modelsimproved ways to develop applications?
![Page 7: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/7.jpg)
Data ModelsKey / Value
memcached, Dynamo
TabularBigTable
Document OrientedMongoDB, CouchDB, JSON stores
![Page 8: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/8.jpg)
Focus on performance
depth of functionality
scalab
ility & perform
ance •memcached
• key/value
• RDBMS
![Page 9: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/9.jpg)
JSON-style Documents
{“hello”: “world”}
\x16\x00\x00\x00\x02hello\x00\x06\x00\x00\x00world\x00\x00
http://bsonspec.org
represented as BSON
![Page 10: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/10.jpg)
Flexible “Schemas”
{“author”: “mike”, “text”: “...”}
{“author”: “eliot”, “text”: “...”, “tags”: [“mongodb”]}
![Page 11: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/11.jpg)
Dynamic Queries
![Page 12: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/12.jpg)
Atomic Update Modifiers
![Page 13: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/13.jpg)
Focus on Performance
![Page 14: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/14.jpg)
Replication
master
slave slaveslave
master slave
master slave
master master
slave master
![Page 15: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/15.jpg)
Auto-sharding
client
mongos ...mongos
mongodmongod
mongod mongod
mongod
mongod...
Shards
mongod
mongod
mongod
ConfigServers
![Page 16: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/16.jpg)
Many Supported Platforms / Languages
![Page 17: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/17.jpg)
Best Use Cases
The WebCaching
The Web
Scaling Out
High Volume
![Page 18: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/18.jpg)
Less Good At
highly transactional
ad-‐hoc business intelligence
problems that require SQL
![Page 19: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/19.jpg)
A Quick Aside
special key
present in all documents
unique across a Collection
any type you want
_id
![Page 20: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/20.jpg)
Post
{author: “mike”, date: new Date(), text: “my blog post...”, tags: [“mongodb”, “intro”]}
![Page 21: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/21.jpg)
Comment
{author: “eliot”, date: new Date(), text: “great post!”}
![Page 22: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/22.jpg)
New Post
post = {author: “mike”, date: new Date(), text: “my blog post...”, tags: [“mongodb”, “intro”]}
db.posts.save(post)
![Page 23: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/23.jpg)
Embedding a Comment
c = {author: “eliot”, date: new Date(), text: “great post!”}
db.posts.update({_id: post._id}, {$push: {comments: c}})
![Page 24: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/24.jpg)
Posts by Author
db.posts.find({author: “mike”})
![Page 25: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/25.jpg)
Last 10 Posts
db.posts.find() .sort({date: -‐1}) .limit(10)
![Page 26: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/26.jpg)
Posts Since April 1
april_1 = new Date(2010, 3, 1)
db.posts.find({date: {$gt: april_1}})
![Page 27: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/27.jpg)
Posts Ending With ‘Tech’
db.posts.find({text: /Tech$/})
![Page 28: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/28.jpg)
Posts With a Tagdb.posts.find({tags: “mongodb”})
...and Fastdb.posts.ensureIndex({tags: 1})
(multi-‐key indexes)
![Page 29: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/29.jpg)
Indexing / Querying on Embedded Docs
db.posts.ensureIndex({“comments.author”: 1})
db.posts.find({“comments.author”: “eliot”})
(dot notation)
![Page 30: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/30.jpg)
Counting Posts
db.posts.count()
db.posts.find({author: “mike”}).count()
![Page 31: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/31.jpg)
Basic Paging
page = 2page_size = 15
db.posts.find().limit(page_size) .skip(page * page_size)
![Page 32: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/32.jpg)
Migration: Adding Titles
post = {author: “mike”, date: new Date(), text: “another blog post...”, tags: [“mongodb”], title: “MongoDB for Fun and Profit”}
post_id = db.posts.save(post)
(just start adding them)
![Page 33: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/33.jpg)
$gt, $lt, $gte, $lte, $ne, $all, $in, $nin
db.posts.find({$where: “this.author == ‘mike’ || this.title == ‘foo’”})
Advanced Queries
![Page 34: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/34.jpg)
Other Cool Stuffaggregation and map/reduce
capped collections
unique indexes
mongo shell
GridFS
geo
![Page 35: Introduction to MongoDB](https://reader033.fdocuments.in/reader033/viewer/2022051400/54be755f4a79597e7b8b45fa/html5/thumbnails/35.jpg)
Download MongoDBhttp://www.mongodb.org
and let us know what you think@mdirolf @mongodb
slides will be up on http://dirolf.com