0
Getting started with


MongoDB
Introduction
Introduction
Relational
Database
Introduction
                            Document
Relational
                            Orientated
Database
             ...
Introduction
                             Document
Relational
                             Orientated
Database
           ...
What is MongoDB?

•   Scalable high-performance open source, document-
    orientated database
•   Built for speed
•   Ric...
Why use MongoDB?


•   SQL was invented in the 70’s to store data
•   MongoDB stores documents / objects
•   We work with ...
What its great for


•   Websites
•   Caching
•   High scalability
•   Storage of program objects and JSON
What its not great for


•   Highly transactional applications
•   Problems requiring SQL
Differences
When I Say

Database
When I Say     Think

Database     Database
When I Say                               Think

    Database                             Database


•   Made up of multipl...
When I Say

Collection
When I Say   Think

Collection    Table
When I Say                               Think

    Collection                                 Table

•   Schema-less
•   ...
When I Say

Document
When I Say       Think

Document      Record / Row
When I Say                              Think

    Document                        Record / Row

•   Stored in a collectio...
When I Say                               Think

    Document                         Record / Row

•   Stored in a collect...
Relations
Referential / Normalised


•   Same as SQL
•   “First class” objects that are at top level
•   Many to many relationships
...
# Post
                               {

                                   title: “Getting started with MongoDB”,

      ...
Embedded


•   Embedded is pre-joining
•   Embed when document always appears with parent
•   4MB document size limit



 ...
# Posts
        {
            title: “Getting started with MongoDB”,

            body: “blah blah blah ... “,

          ...
Ruby   MongoDB
MongoMapper
              http://github.com/jnunemaker/mongomapper




•   Typecasting
•   Callbacks (ActiveSupport Callba...
http://www.mongoid.org




•   Named scopes / chainable criteria
•   Versioning of your documents
•   Full callback suppor...
Demo
Conclusions




•   NoSQL is pretty scary / We’re used to SQL
•   It’s the future.
Chat to us online:



twitter: @platform45
Discussion
Introduction to MongoDB
Upcoming SlideShare
Loading in...5
×

Introduction to MongoDB

3,791

Published on

Talk on MongoDB at local Ruby meetup

Published in: Technology
0 Comments
11 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,791
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
93
Comments
0
Likes
11
Embeds 0
No embeds

No notes for slide


  • Old man - SQL
    DoD - MongoDB
  • Old man - SQL
    DoD - MongoDB
  • Old man - SQL
    DoD - MongoDB
  • Document Orientated: It isnt stored as records and tables, information stored as documents or objects
    Build for speed: No transaction log / removed anything that would slow it down
    Rich document based queries: Users can find documents based on any search criteria / similar to SQL
    Full index support: Index on any attribute - similar to SQL
    Replication and failover: Supports replication of data between servers for failover and redundancy
    Auto sharding: Scale horizontally without compromising functionality - EVERY EASY - NO JOINS
    Map Reduce - Database itself can perform advanced aggregation and data processing

  • Websites: Object orientated programming languages - Easy persistence of objects
    Caching: Extremely fast
    High scalability: Easy Auto sharding and replication and failover

  • * SQL writes to transaction log (for data durability)
    * Performance loss
    * MongoDB doesn’t do this - Uses replication
  • Similarities and Differences between SQL and document orientated databases
  • No need for any rake db:creates or rake db:setup
  • No need for any rake db:creates or rake db:setup
  • Like a table in MySQL
    EXCEPT!!!
    Capped collections: Extremely fast, atomic writes, good for log files
  • Like a table in MySQL
    EXCEPT!!!
    Capped collections: Extremely fast, atomic writes, good for log files



  • Next up is relations - which is one of the major differences or advantages over SQL
  • First class - objects that can stand alone (users -> blog posts)
  • Similar to MySQL
    Tags: Array of ID’s Many to many
    Comments: belongs_to / has_many


  • Using mongodb with ruby
  • First up:

    Mongomapper
    by jnunemaker
    Works for OrderedList

    Typecasting: Mongodb doesnt understand types - MongoMapper creates the typecasting
  • Durran - Hashrocket




  • Transcript of "Introduction to MongoDB"

    1. 1. Getting started with MongoDB
    2. 2. Introduction
    3. 3. Introduction Relational Database
    4. 4. Introduction Document Relational Orientated Database Database
    5. 5. Introduction Document Relational Orientated Database Database NoSQL Bra.
    6. 6. What is MongoDB? • Scalable high-performance open source, document- orientated database • Built for speed • Rich document based queries • Full index support • Replication and Failover • Auto Sharding • Map / Reduce
    7. 7. Why use MongoDB? • SQL was invented in the 70’s to store data • MongoDB stores documents / objects • We work with objects (Ruby) • We need databases to persist our objects • So why not just store objects directly?
    8. 8. What its great for • Websites • Caching • High scalability • Storage of program objects and JSON
    9. 9. What its not great for • Highly transactional applications • Problems requiring SQL
    10. 10. Differences
    11. 11. When I Say Database
    12. 12. When I Say Think Database Database
    13. 13. When I Say Think Database Database • Made up of multiple collections • Are created on-the-fly when first referenced
    14. 14. When I Say Collection
    15. 15. When I Say Think Collection Table
    16. 16. When I Say Think Collection Table • Schema-less • Indexable by one or more keys • Created on-the-fly when first referenced • Capped collections: Fixed size, older records dropped after limit reached
    17. 17. When I Say Document
    18. 18. When I Say Think Document Record / Row
    19. 19. When I Say Think Document Record / Row • Stored in a collection • Can have _id key - Works like primary keys in MySQL • Supports relationships: embedded or referential • Document storage in BSON
    20. 20. When I Say Think Document Record / Row • Stored in a collection • Can have _id key - Works like primary keys in MySQL • Supports relationships: embedded or referential • Document storage in BSON JSONS Binary Brother
    21. 21. Relations
    22. 22. Referential / Normalised • Same as SQL • “First class” objects that are at top level • Many to many relationships has_many User Blog Post belongs_to
    23. 23. # Post { title: “Getting started with MongoDB”, body: “blah blah blah ... “, created: Date(’09-06-2010’), tags: [1, 2] } # Comments # Tags { { id: 1, body: “I did not have relations..”, name: “example” user_id: 1, }, { post_id: 1, id: 2, created: Date(’09-06-2010’), name: “lol” } }
    24. 24. Embedded • Embedded is pre-joining • Embed when document always appears with parent • 4MB document size limit Blog Post Post Title Post Body Comments
    25. 25. # Posts { title: “Getting started with MongoDB”, body: “blah blah blah ... “, created: Date(’09-06-2010’), Array tags: [ ‘example’, ‘bill clinton’ ], comments: [ { author: “Bill”, comment: “I did not have relations” }, { author: “Monica”, comment: “LOL” } ] } Array of hashes
    26. 26. Ruby MongoDB
    27. 27. MongoMapper http://github.com/jnunemaker/mongomapper • Typecasting • Callbacks (ActiveSupport Callbacks) • Validations • Connection and database can differ per document • Has create, update methods • Find: id, ids, :all, :first, :last • Associations (has_one, has_many, many_to_many)
    28. 28. http://www.mongoid.org • Named scopes / chainable criteria • Versioning of your documents • Full callback support on documents AND embedded documents • Proper master/slave distribution • Optimised for use with extremely large datasets This is what we use!
    29. 29. Demo
    30. 30. Conclusions • NoSQL is pretty scary / We’re used to SQL • It’s the future.
    31. 31. Chat to us online: twitter: @platform45
    32. 32. Discussion
    1. A particular slide catching your eye?

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

    ×