PostgreSQL MongoDB CTO @basuke
not only but also
http://www.assiston.co.jp/ • • ~1000 • 30~80 PV
• • • • Google
• • • •
MongoDB ( )
• PostgreSQL 7.4 => 8.1 • PHP 4.3 => 4.4 => 5.1 •
• MongoDB 1.6.3 • PHP 5.3 • Lithium • •
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/

PostgreSQLからMongoDBへ

  • 1.
  • 2.
  • 4.
  • 5.
  • 6.
  • 7.
  • 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.
  • 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 ongithub • https://github.com/mongodb/mongo/tree/ master/jstests • MongoDB JavaScript
  • 25.