SlideShare a Scribd company logo
PostgreSQL
MongoDB

        CTO
      @basuke
not only
but also
PostgreSQLからMongoDBへ
http://www.assiston.co.jp/

•

•           ~1000

•   30~80   PV
•

•

•

• Google
•

•

•

•
MongoDB
  (   )
PostgreSQLからMongoDBへ
•   PostgreSQL 7.4 => 8.1

•   PHP 4.3 => 4.4 => 5.1

•
•   MongoDB 1.6.3

•   PHP 5.3

•   Lithium

•
•
PostgreSQLからMongoDBへ
Lithium

•   http://lithify.me/

•   5.3

•   CakePHP

•   MongoDB / CouchDB

•   ↑                    RDB   w
PHP            MongoDB


 •   Lithium

 •         pecl   mongo

     •
Item::find('all', array(

   
 
 'conditions' => array(

   
 
 
 'category' => $tag,

   
 
 
 'visible' => true,

   
 
 ),

   
 
 'order' => array(

   
 
 
      
   
 'position'=>'DESC', 'id' => 'DESC'),

   
 ));
$item_collection->find(array(

   
 
 'category' => $tag,

   
 
 'visible' => true,

   
 )).sort(array(

   
 
 'position'=>-1, 'id' => -1),

   
 ));
•   mongoimport / mongoexport

    •   JSON

    •                 JSON

•   PHP

•
•
•   mongoimport -d assiston -c items --drop --file
    items.dump

    {"no" : 123456, "items" : [{"at" : 1285679232000}}
Mongo Extended JSON

•   http://www.mongodb.org/display/DOCS/Mongo
    +Extended+JSON

•                 $binary, $date, $oid

•        $date      milliseconds

    •   PHP      32bit int
•
    •   PHP JSON

•   TIMESTAMP                          json_encode



    •   '2010-12-10 17:20:21' => 1291969221

    •   1291969221 sec => "||date:1291969221000||"

    •   JSON

    •   "||date:1291969221000||" => Date(1291969221000)
•   PHP           w

    •   Python        OK

    •   pgmongo
1: atomic
•
•
    •

•
CREATE TABLE ORDERS (
 id SERIAL PRIMARY KEY,
 total INTEGER NOT NULL,     {
 ...                          no: integer,
);                            total: integer,
                              items: [
CREATE TABLE ORDER_ITEMS (     { price: integer, ...},
 id SERIAL PRIMARY KEY,
                              ]
 order_id INTEGER
                               ...
   REFERS TO ORDERS,
                             }
 price INTEGER NOT NULL,
 ...
);
2:
•   ObjectID

•
•   function(seqname) { return
    db.sequences.findAndModify({ query:{_id:seqname},
    update: {$inc: {val:1}}, upsert: true, 'new': true}).val; }

•   db.system.js

    •   db.eval("return sequence('abc')")
3: mongo on github


•   https://github.com/mongodb/mongo/tree/
    master/jstests

•   MongoDB      JavaScript
Thank you.
http://basuke.com/

More Related Content

PostgreSQLからMongoDBへ

  • 1. PostgreSQL MongoDB CTO @basuke
  • 9. PostgreSQL 7.4 => 8.1 • PHP 4.3 => 4.4 => 5.1 •
  • 10. MongoDB 1.6.3 • PHP 5.3 • Lithium • •
  • 12. Lithium • http://lithify.me/ • 5.3 • CakePHP • MongoDB / CouchDB • ↑ RDB w
  • 13. PHP MongoDB • Lithium • pecl mongo •
  • 14. Item::find('all', array( 'conditions' => array( 'category' => $tag, 'visible' => true, ), 'order' => array( 'position'=>'DESC', 'id' => 'DESC'), ));
  • 15. $item_collection->find(array( 'category' => $tag, 'visible' => true, )).sort(array( 'position'=>-1, 'id' => -1), ));
  • 16. mongoimport / mongoexport • JSON • JSON • PHP • •
  • 17. mongoimport -d assiston -c items --drop --file items.dump {"no" : 123456, "items" : [{"at" : 1285679232000}}
  • 18. Mongo Extended JSON • http://www.mongodb.org/display/DOCS/Mongo +Extended+JSON • $binary, $date, $oid • $date milliseconds • PHP 32bit int
  • 19. • PHP JSON • TIMESTAMP json_encode • '2010-12-10 17:20:21' => 1291969221 • 1291969221 sec => "||date:1291969221000||" • JSON • "||date:1291969221000||" => Date(1291969221000)
  • 20. PHP w • Python OK • pgmongo
  • 21. 1: atomic • • • •
  • 22. CREATE TABLE ORDERS ( id SERIAL PRIMARY KEY, total INTEGER NOT NULL, { ... no: integer, ); total: integer, items: [ CREATE TABLE ORDER_ITEMS ( { price: integer, ...}, id SERIAL PRIMARY KEY, ] order_id INTEGER ... REFERS TO ORDERS, } price INTEGER NOT NULL, ... );
  • 23. 2: • ObjectID • • function(seqname) { return db.sequences.findAndModify({ query:{_id:seqname}, update: {$inc: {val:1}}, upsert: true, 'new': true}).val; } • db.system.js • db.eval("return sequence('abc')")
  • 24. 3: mongo on github • https://github.com/mongodb/mongo/tree/ master/jstests • MongoDB JavaScript

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n