nonSQL databases     alexey gaziev
RDBMS• Great for many apps• Shortcomings  • Scalability  • Flexibility
Other DBMS• Flat file• Hierarchical• Network• Document-oriented• Object-oriented
CAP Theorem                                          Pick twoС             A                        • Consistency         ...
ACID & BASE• Atomicity     • Basically Available• Consistency   • Soft state• Isolation     • Eventually consistent• Durab...
ACID vs. BASE    ACID                      BASE•   Strong consistency    •   Weak consistency•   Isolation             •  ...
Scalability &                IntroPerformance                memcached                   Key/Values store                 ...
Features• Collection oriented storage: easy storage of object/  JSON -style data• Dynamic queries• Full index support, inc...
Great for• Websites• Caching• High volume, low value• High scalability• Storage of program objects and json
Not as great for• Highly transactional• Ad-hoc business intelligence• Problems requiring SQL
Installation
Collection• Think table, but with no schema• For grouping into smaller query sets (speed)• Each top entity in your app wou...
Document• Stored in collection, think record or row• Can have _id key that works like primary key in MySQL• Two options fo...
Storage (BSON){ author: joe,  created: Date(03-28-2009),  title: Yet another blog post,  text: Here is the text...,  tags:...
Basics$ bin/mongod &$ bin/mongo...> use mydb> j = { name: "mongo"};{"name" : "mongo"}> t = { x : 3 };{ "x" : 3 }> db.thing...
Querying•   db.collection.find({‘first_name’: ‘John’}) # finds all Johns•   db.collection.find({‘first_name’: /^J/}) # regex•  ...
Querying 2•   $in, $nin, $all, $ne, $gt, $gte, $lt, $lte, $size, $where•   :fields (like :select in active record)•   :limi...
Dynamic querying
Ruby support• mongo-ruby-driver  • Pure Ruby, with optional C extension• MongoRecord  • ORM like functionality• Other mapp...
Ruby basics• Connect:  • db = Mongo.new.db(‘my-database’)  • coll = db.collection(‘players’)• Insert:  • coll.insert (“nam...
Grid FS• File storage in MongoDB• IO-like API for Ruby
Other cool stuff• Capped collections• Upserts• Multikeys
Resources• http://spitfiresky.com/blog/recap-of-my-sdruby- presentation-on-mongodb.html• http://railstips.org/2009/6/3/what...
Resources 2• http://api.mongodb.org/ruby/0.15.1/index.html• http://www.engineyard.com/blog/2009/ mongodb-a-light-in-the-da...
thanks!
Mongodb my
Upcoming SlideShare
Loading in...5
×

Mongodb my

868

Published on

Presentation for piterrb about non-sql db with accent on mongodb

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
868
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Mongodb my

  1. 1. nonSQL databases alexey gaziev
  2. 2. RDBMS• Great for many apps• Shortcomings • Scalability • Flexibility
  3. 3. Other DBMS• Flat file• Hierarchical• Network• Document-oriented• Object-oriented
  4. 4. CAP Theorem Pick twoС A • Consistency • Availability P • Tolerance to network Partitions http://www.cs.berkeley.edu/~brewer/cs262b-2004/PODC-keynote.pdf
  5. 5. ACID & BASE• Atomicity • Basically Available• Consistency • Soft state• Isolation • Eventually consistent• Durability
  6. 6. ACID vs. BASE ACID BASE• Strong consistency • Weak consistency• Isolation • Availability first• Focus on “commit” • Best effort• Nested transactions • Approximate answers• Availability? • Agressive (optimistic)• Conservative • Simpler!• Difficult evolution • Faster (schema) • Easier evolution
  7. 7. Scalability & IntroPerformance memcached Key/Values store RDBMS Depth of Functionality
  8. 8. 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
  9. 9. Great for• Websites• Caching• High volume, low value• High scalability• Storage of program objects and json
  10. 10. Not as great for• Highly transactional• Ad-hoc business intelligence• Problems requiring SQL
  11. 11. Installation
  12. 12. 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
  13. 13. 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
  14. 14. 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 } ]}
  15. 15. 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"}>
  16. 16. 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’})
  17. 17. 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)
  18. 18. Dynamic querying
  19. 19. Ruby support• mongo-ruby-driver • Pure Ruby, with optional C extension• MongoRecord • ORM like functionality• Other mappers
  20. 20. Ruby basics• Connect: • db = Mongo.new.db(‘my-database’) • coll = db.collection(‘players’)• Insert: • coll.insert (“name” => “mike”, “age” => ...• Query: • coll.find (“age” => 35)
  21. 21. Grid FS• File storage in MongoDB• IO-like API for Ruby
  22. 22. Other cool stuff• Capped collections• Upserts• Multikeys
  23. 23. 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
  24. 24. 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
  25. 25. thanks!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×