MongoDB Revised Sharding Guidelines MongoDB 3.x_Kimberly_Wilkins
MongoDB
-
Upload
spbruby -
Category
Technology
-
view
1.408 -
download
1
description
Transcript of MongoDB
![Page 1: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/1.jpg)
nonSQL databasesalexey gaziev
![Page 2: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/2.jpg)
RDBMS
• Great for many apps
• Shortcomings
• Scalability
• Flexibility
![Page 3: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/3.jpg)
Other DBMS
• Flat file
• Hierarchical
• Network
• Document-oriented
• Object-oriented
![Page 4: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/4.jpg)
CAP Theorem
• Consistency
• Availability
• Tolerance to network Partitions
Pick two
http://www.cs.berkeley.edu/~brewer/cs262b-2004/PODC-keynote.pdf
С A
P
![Page 5: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/5.jpg)
ACID & BASE
• Atomicity
• Consistency
• Isolation
• Durability
• Basically Available
• Soft state
• Eventually consistent
![Page 6: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/6.jpg)
ACID vs. BASE
• Strong consistency
• Isolation
• Focus on “commit”
• Nested transactions
• Availability?
• Conservative
• Difficult evolution (schema)
• Weak consistency
• Availability first
• Best effort
• Approximate answers
• Agressive (optimistic)
• Simpler!
• Faster
• Easier evolution
ACID BASE
![Page 7: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/7.jpg)
![Page 8: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/8.jpg)
Intro
Key/Values store
memcached
RDBMS
Depth of Functionality
Scalability & Performance
![Page 9: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/9.jpg)
Features• Collection oriented storage: easy storage of object/
JSON -style data• Dynamic queries• Full index support, including on inner objects and
embedded arrays• Query profiling• Replication and fail-over support• Efficient storage of binary data including large objects (e.g. photos and videos)
• Auto-sharding for cloud-level scalability (currently in alpha)
• Commercial support available
![Page 10: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/10.jpg)
Great for
• Websites
• Caching
• High volume, low value
• High scalability
• Storage of program objects and json
![Page 11: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/11.jpg)
Not as great for
• Highly transactional
• Ad-hoc business intelligence
• Problems requiring SQL
![Page 12: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/12.jpg)
Installation
![Page 13: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/13.jpg)
Collection
• Think table, but with no schema
• For grouping into smaller query sets (speed)
• Each top entity in your app would have its own collection (users, articles, etc.)
• Full index support
![Page 14: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/14.jpg)
Document
• Stored in collection, think record or row
• Can have _id key that works like primary key in MySQL
• Two options for relationships: subdocument or db reference
![Page 15: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/15.jpg)
Storage (BSON)
{ author: 'joe', created: Date('03-28-2009'), title: 'Yet another blog post', text: 'Here is the text...', tags: [ 'example', 'joe' ], comments: [ { author: 'jim', comment: 'I disagree' }, { author: 'nancy', comment: 'Good post' } ]}
![Page 16: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/16.jpg)
Basics$ bin/mongod &$ bin/mongo...> use mydb> j = { name: "mongo"};{"name" : "mongo"}> t = { x : 3 };{ "x" : 3 }> db.things.save(j);> db.things.save(t);> db.things.find();in cursor for : DBQuery: example.things ->{"name" : "mongo" , "_id" : "497cf60751712cf7758+dbb"}{"x" : 3 , "_id" : "497cf61651712cf7758+dbc"}>
![Page 17: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/17.jpg)
Querying
• db.collection.find({‘first_name’: ‘John’}) # finds all Johns
• db.collection.find({‘first_name’: /^J/}) # regex
• db.collection.find_first({‘_id’:1}) # finds first with _id of 1
• db.collection.find({‘age’: {‘$gt’: 21}}) # finds possible drinkers
• db.collection.find({‘author.first_name’:‘John’}) # subdocument
• db.collection.find({$where:‘this.age >= 6 && this.age <= 18’})
![Page 18: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/18.jpg)
Querying 2
• $in, $nin, $all, $ne, $gt, $gte, $lt, $lte, $size, $where
• :fields (like :select in active record)
• :limit, :offset for pagination
• :sort ascending or descending [[‘foo’, 1], [‘bar’, -1]]
• count and group (uses map/reduce)
![Page 19: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/19.jpg)
Dynamic querying
![Page 20: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/20.jpg)
Ruby support
• mongo-ruby-driver
• Pure Ruby, with optional C extension
• MongoRecord
• ORM like functionality
• Other mappers
![Page 21: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/21.jpg)
Ruby basics
• Connect:
• db = Mongo.new.db(‘my-database’)
• coll = db.collection(‘players’)
• Insert:
• coll.insert (“name” => “mike”, “age” => ...
• Query:
• coll.find (“age” => 35)
![Page 22: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/22.jpg)
Grid FS
• File storage in MongoDB
• IO-like API for Ruby
![Page 23: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/23.jpg)
Other cool stuff
• Capped collections
• Upserts
• Multikeys
![Page 24: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/24.jpg)
Resources
• http://spitfiresky.com/blog/recap-of-my-sdruby-presentation-on-mongodb.html
• http://railstips.org/2009/6/3/what-if-a-key-value-store-mated-with-a-relational-database-system
• http://www.mongodb.org/display/DOCS/Production+Deployments
• http://www.mongohq.com/home
![Page 25: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/25.jpg)
Resources 2
• http://api.mongodb.org/ruby/0.15.1/index.html
• http://www.engineyard.com/blog/2009/mongodb-a-light-in-the-darkness-key-value-stores-part-5
• http://queue.acm.org/detail.cfm?id=1394128
![Page 26: MongoDB](https://reader033.fdocuments.net/reader033/viewer/2022051314/54bf76f14a795940398b457a/html5/thumbnails/26.jpg)
thanks!