English Casual
I started to use MongoDB
         2012/05/10
           riywo
Developing Web App
❖   I wanted to build a Web App

❖   Renewal of Management Tool

    ❖   High performance is unnecessary

❖   Present: MySQL Schema

    ❖   Too many relations

    ❖   Fuckin’!!!
SELECT u.name, c.name, a.code ...
FROM users u
LEFT JOIN map USING(user_id)
LEFT JOIN classes c USING(class_id)
LEFT JOIN addresses a USING(user_id)
WHERE c.categ = ?
AND u.age >= ? AND ...
Schema less!!
Features of MongoDB
            “Schema-less”
❖   MongoDB stores “documents” as BSON(binary JSON)

    ❖   without CREATE TABLE or ALTER TABLE

    ❖   TABLE => collection, RECORD => document

❖   Powerful Query

    ❖   next...
db.users.find(
  {address.city:{$in:["tokyo",...]}},
  {name:1}
).sort({age:-1}).limit(10).skip(5)
Features of MongoDB
            “Schema-less”

❖   Point: “Denormalize” as much as you can

    ❖   not using relation or mapping table

    ❖   embedding to the document’s column

❖   ...Why?
Features of MongoDB
             “no JOIN”
❖   MongoDB doesn’t support JOIN !

❖   If you want to JOIN multi collections, you should do it
    on application side

    ❖   find document => lookup reference => find document

    ❖   some drivers support DBRef, but it is just format...

        ❖   hoge: { $ref:"coll", $id:"id" }

❖   So, intentional embedding relational documents is better
Features of MongoDB
          “no Transaction”
❖   MongoDB doesn’t support transaction !

❖   MongoDB is designed for updating “one” document

    ❖   some Atomic operations($inc, findAndModify)

❖   It is difficult to update multi documents Atomically

    ❖   MongoDB update likes MySQL AUTOCOMMIT
                                  ’s
Features of MongoDB
          “no Transaction”
❖   If you want to update multi documents ACID-ly...

    ❖   !!! You should compromise some aspects !!!

    ❖   Optimistic/Pessimistic Lock

    ❖   Two Phase Commit

    ❖   MVCC if possible...
Noooooooo!
I ♡ RDBMS
❖   RDBMS have great transaction function

❖   Safe for many trouble scenes

❖   But RDBMS have some weak points

    ❖   which are hot spots of NoSQL!

❖   So, I should learn about Database more and more

    ❖   I bought “Database Management Systems”

    ❖   Let’s read it with me!
Thanks

English Casual 2012/05/10

  • 1.
    English Casual I startedto use MongoDB 2012/05/10 riywo
  • 2.
    Developing Web App ❖ I wanted to build a Web App ❖ Renewal of Management Tool ❖ High performance is unnecessary ❖ Present: MySQL Schema ❖ Too many relations ❖ Fuckin’!!!
  • 3.
    SELECT u.name, c.name,a.code ... FROM users u LEFT JOIN map USING(user_id) LEFT JOIN classes c USING(class_id) LEFT JOIN addresses a USING(user_id) WHERE c.categ = ? AND u.age >= ? AND ...
  • 4.
  • 5.
    Features of MongoDB “Schema-less” ❖ MongoDB stores “documents” as BSON(binary JSON) ❖ without CREATE TABLE or ALTER TABLE ❖ TABLE => collection, RECORD => document ❖ Powerful Query ❖ next...
  • 6.
    db.users.find( {address.city:{$in:["tokyo",...]}}, {name:1} ).sort({age:-1}).limit(10).skip(5)
  • 7.
    Features of MongoDB “Schema-less” ❖ Point: “Denormalize” as much as you can ❖ not using relation or mapping table ❖ embedding to the document’s column ❖ ...Why?
  • 8.
    Features of MongoDB “no JOIN” ❖ MongoDB doesn’t support JOIN ! ❖ If you want to JOIN multi collections, you should do it on application side ❖ find document => lookup reference => find document ❖ some drivers support DBRef, but it is just format... ❖ hoge: { $ref:"coll", $id:"id" } ❖ So, intentional embedding relational documents is better
  • 9.
    Features of MongoDB “no Transaction” ❖ MongoDB doesn’t support transaction ! ❖ MongoDB is designed for updating “one” document ❖ some Atomic operations($inc, findAndModify) ❖ It is difficult to update multi documents Atomically ❖ MongoDB update likes MySQL AUTOCOMMIT ’s
  • 10.
    Features of MongoDB “no Transaction” ❖ If you want to update multi documents ACID-ly... ❖ !!! You should compromise some aspects !!! ❖ Optimistic/Pessimistic Lock ❖ Two Phase Commit ❖ MVCC if possible...
  • 11.
  • 12.
    I ♡ RDBMS ❖ RDBMS have great transaction function ❖ Safe for many trouble scenes ❖ But RDBMS have some weak points ❖ which are hot spots of NoSQL! ❖ So, I should learn about Database more and more ❖ I bought “Database Management Systems” ❖ Let’s read it with me!
  • 13.

Editor's Notes