SlideShare a Scribd company logo
1 of 62
How to use MongoDB
   with CakePHP

          2010/9/4
         Cakefest2010


       Yasushi Ichikawa
TOPIC

1. Who am I
2. MongoDB
3. PHP + MongoDB
4. CakePHP + MongoDB
Yasushi Ichikawa
Twitter: @ichikaway

Call me ichi
My Code
•    I've used Cakephp since Aug 2008.
•    Author of the SQL Explain Component
    → One of Debug_kit Contributors
•    Author of the Cakephp MongoDB-Datasource
My Code


    My code for Cakephp
    
        http://github.com/ichikaway
TOPIC

1. Who am I
2. MongoDB
3. PHP + MongoDB
4. CakePHP + MongoDB
MongoDB is
One of NoSQL
MongoDB
•    Open-source non-relational DB
•    C++
•    GNU AGPL v3.0
•    Many Drivers(PHP, Perl, Ruby, etc)
    – Apache License
•    Company: 10gen
• Download (version 1.6.2)
    – http://www.mongodb.org/display/DOCS/Downloads
MongoDB TERMs

 RDB       MongoDB

Table      Collection

 Row       Document

Column       Field
MongoDB Position




• Performance
  – Key/Value > mongoDB >>> RDBMS
• Functionality
  – RDBMS > mongoDB >>> Key/Value
MongoDB Provides


• Scalability
• Queryable
• Read/Write FAST
• Schema Free
MongoDB Schema

• Document: bson (similar json)
 – Binary data
• Schema Free
 – different schema in same collection
                            Id, title, body

                          Id, name, tel, fax

                      Id, name, nickname, email

                           Posts collection
MongoDB Schema

• Embedded Object
                  Posts collection

  id: 1, name: ichikaway, tel: 090-1111-2222. fax:
          Address                  skill
      Country: Japan,          Java: 2years,
      Zip: 222-3333            PHP: 3years

  id: 2, name: Yasushi, tel: 090-3333-4444. fax:
   id: 3, name: Ninjaaa, tel: 090-5555-6666. fax:
RDB Schema
• RDB schema
   • Natural data structure??
  Screen
Blog                    Blog table   Tags table

Title                   Title        Tag1
Text                    Text         Tag2
                                     Tag3
tag1,tag2,tag3    RDB
                                 Comment Table
Comment1
Comment2                         Comment1
Comment3                         Comment2
                                 Comment3
MongoDB schema
• Schema Free
  – Natural data structure
  Screen
Blog                     Blog collection
Title                    Title : xxxx
Text                     Text : yyyy
tag1,tag2,tag3   Mongo   Tag: [tag1,tag2,tag3]
                         Comment:
                         [comment1,
Comment1                   comment2,
Comment2                   comment3
Comment3                 ]
MongoDB In Production




github, heroku(MongoHQ), etc
MongoDB Production Case
• Business insider
• http://www.businessinsider.com/how-we-use-mongodb-2009-11

• Over 600,000 PV / business day
• 3 apache + 1 mongoDB
• MongoDB uses under 5% cpu time
MongoDB Fit or Not




Not replace all RDBMS
MongoDB Not FIT
 • Need Join
 • Need Transaction
 • Small disk space
    – each record has field label data
                         Posts collection
        id: 1, name: ichikaway, tel: 090-1111-2222. fax:

6bytes id: 2,   name: Yasushi, Age: 20 . Tel: 111-2222
        id: 3, name: Ninjaaa, Language: Japanese
MongoDB Fit
• Need Performance
  – Read/Write is fast
• Scale out
  – Master/Slave
  – Replica set(Automatic Failover)
  – Sharding
How to use
MongoDB Retrieving Data

SELECT field1, field2 From blog WHERE field1 = 'aaa';



db.blog.find( { field1 : ”aaa” }, { field1 : 1, field2 : 1 } )



  Collection name
MongoDB Retrieving Data

SELECT * WHERE field1 > 3
ORDER BY field2 DESC
LIMIT 10, 20;


db.collection.find( { field1 : { $gt:3 } } )
.sort(field2: -1)
.skip(10)
.limit(20);
MongoDB find operators
• $gt, $gte
• $lt, $lte
• $ne
• $in
• $nin
• $or

              http://www.mongodb.org/display/DOCS/Advanced+Queries
MongoDB find tips
•    Regular Expressions
    – { name : /ichikawa.*sushi/i }
•    Embedded Object
    – { "author.name" : "ichikawa" }
                                      Blog collection
                                      Title : xxxx
                                      Text : yyyy
                                      author:
                                      {
                                        name : 'ichikawa',
                                        age : 15
                                      }
MongoDB




DEMO
SQL to Mongo Mapping Chart
http://www.mongodb.org/display/DOCS/SQL+to+Mongo+
Mapping+Chart
MongoDB Indexing
Create Index
db.collection.ensureIndex({“title” : 1})
Delete Index
db.collection.dropIndex({“title” : 1})
Create Embedded Doc Index
db.collection.ensureIndex
({“Autor.name” : 1})
Create Index(Background)
db.collection.ensureIndex
({“title” : 1}, {background:true} )
Cool Stuffs of MongoDB



Geospatial Index
Capped Collection
MongoDB Geospatial Index


    Version 1.3.3+ , recommend 1.6.2+ (Bug fix)

    Calculate location data
    – Latitude(緯度), Longitude(経度)

    find the closest location with Operators
    – $near: sort from the closest point
    – $box: find points within the rectangle
    – $center: find points within the circle
MongoDB Geospatial Index



    Insert data
    db.geotest.save({ loc:[ 35, 139 ] })
                        Latitude Longitude


    create Index
    db.geotest.ensureIndex( {loc:”2d”} )
MongoDB Geospatial Index



    Find the point
    db.geotest.find({ loc:[35, 140] });



    $near
    db.geotest.find({ loc:{ $near : [30, 130] } })
MongoDB Geospatial Index

    $box
    – lower left, upper right
     db.geotest.find({ loc:{ $within:{ $box:
      [[1, 1], [10,10]] }}});

    $center
    – set radius(degree)
     db.geotest.find({ loc:{
       $within:{ $center:       [[10, 10], 0.1 ] }
                                          radius(degree)
      }})
MongoDB Geospatial Index




     DEMO
MongoDB Capped Collection


  Creating a Fixed Size (capped) Collection

  Not think about data space / overflow
• Age out data is deleted when Collection is full
• Good for
    – Logging
    – Caching


 db.createCollection("testcap1", {capped: true, size:5000});
MongoDB Attension




    32bit version limitation
    –can't save data over 2Gbytes
MongoDB Books




      http://www.mongodb.org/display/DOCS/Books
TOPIC

1. Who am I
2. MongoDB
3. PHP + MongoDB
4. CakePHP + MongoDB
Pecl Mongo Driver

• Apache License
• Setup
 pecl install mongo
 extension=mongo.so (php.ini)
• Manual
 –http://us2.php.net/mongo
Pecl Mongo
•   Connect
     $mongo = new Mongo(localhost:27017);
     $db = $mongo->selectDB('blog');

•   select collection
    $collection = $db->selectCollection('posts');
•   Find
    $collection->find($cond, $filed)
         ->sort()->limit(5)->skip();
Pecl Mongo
    $data = array('field1' => 'val1',
                  'field2' => 'val2');
•    Insert
    $collection->insert($data);

•    Update
    $new = array('$set' => array('field2' => 'aa'));
    $cond = array('field1' => 'val1');
    $collection->update($cond, $new);
TOPIC

1. Who am I
2. MongoDB
3. PHP + MongoDB
4. CakePHP + MongoDB
MongoDB Datasource

    Developed since Jan, 2010

    PHP5+

    Pecl Mongo

    CakePHP1.2+
     – Recommend Cake1.3
MongoDB Datasource

    Version 0.3
      – set schema info to Model::schema
      – test cases

    Version 0.4
      – create schema info from Post data
      – show command log

        Huge Thanks AD7six
Cake Datasource

  The link between models and the
  source(DB)

  Transparency
    – Use Mongo from Model methods
    – connect to MongoDB and use
       collection automatically
Cake calls Datasource methods

 Model Method   Datasource

    find()        read()

    save()       create()

    save()       update()

   delete()      delete()
Let's use
Setup

  cd app/plugins

  git clone
  http://github.com/ichikaway/mongoDB-
  Datasource.git mongodb

  cd app/config

  vi database.php
database.php

<?php
class DATABASE_CONFIG {
 public $default = array(
   'driver' => 'mongodb.mongodbSource',
   'database' => 'cakemongo1',
   'host' => 'localhost',
   'port' => 27017,
 );
Sample Cake Mongo




   DEMO
 Sample1
Sample2
Sample Cake Mongo part 2

    Delete History
      
         Main data is stored in MySQL
      
         save deleted records in history table
      
         search history records
Sample Cake Mongo part 2

                      MySQL
  App             Default Schema
CakePHP
               Post table   User table
Sample Cake Mongo part 2

    RDB way
     
          copy schema(all table)
Sample Cake Mongo part 2

                                MySQL
  App                        Default Schema
CakePHP
                          Post table   User table
              1. Delete


                              Copy Schema

                          Post table   User table
    2. save
Sample Cake Mongo part 2

    RDB way
     
          copy schema(all table)
            
                Hard to maintain both schema
     
          serialize deleted record, save in history table
            
                Hard to search in history table
Sample Cake Mongo 2




Mongo Way
Sample Cake Mongo part 2

                               MySQL
  App                       Default Schema
CakePHP
                         Post table   User table
             1. Delete

                             MongoDB
                           History Collection
                         {'post' : Post record}
   2. save               {'user' : User record}
Sample Cake Mongo 2




    DEMO
Sample Cake Mongo 2

    Good Fit Document Database
      –   save different table records in one collection

    Don't need prepare schema before Save

    Search easily in History Collection
Summary

    MongoDB
- Good case
- Query
- Geospatial Index
- Capped Collection

    PHP + MongoDB

    CakePHP + MongoDB
Thank you!
     Questions?
Please, speak slowly :)

More Related Content

What's hot

BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and moreBrendan Gregg
 
Delivering a new level of visual performance in an SoC AMD "Raven Ridge" APU
Delivering a new level of visual performance in an SoC AMD "Raven Ridge" APUDelivering a new level of visual performance in an SoC AMD "Raven Ridge" APU
Delivering a new level of visual performance in an SoC AMD "Raven Ridge" APUAMD
 
仮想化専門コンサルタントが教える「成功する仮想化導入のポイント」
仮想化専門コンサルタントが教える「成功する仮想化導入のポイント」仮想化専門コンサルタントが教える「成功する仮想化導入のポイント」
仮想化専門コンサルタントが教える「成功する仮想化導入のポイント」VirtualTech Japan Inc.
 
“Zen 3”: AMD 2nd Generation 7nm x86-64 Microprocessor Core
“Zen 3”: AMD 2nd Generation 7nm x86-64 Microprocessor Core“Zen 3”: AMD 2nd Generation 7nm x86-64 Microprocessor Core
“Zen 3”: AMD 2nd Generation 7nm x86-64 Microprocessor CoreAMD
 
LinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughLinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughThomas Graf
 
데브옵스(DevOps)의 현재와 미래 - ChatOps & VoiceOps (윤석찬)
데브옵스(DevOps)의 현재와 미래 - ChatOps & VoiceOps (윤석찬)데브옵스(DevOps)의 현재와 미래 - ChatOps & VoiceOps (윤석찬)
데브옵스(DevOps)의 현재와 미래 - ChatOps & VoiceOps (윤석찬)Amazon Web Services Korea
 
Heterogeneous Systems Architecture: The Next Area of Computing Innovation
Heterogeneous Systems Architecture: The Next Area of Computing Innovation Heterogeneous Systems Architecture: The Next Area of Computing Innovation
Heterogeneous Systems Architecture: The Next Area of Computing Innovation AMD
 
スケールアップファーストのNoSQL、ScyllaDB(スキュラDB)
スケールアップファーストのNoSQL、ScyllaDB(スキュラDB)スケールアップファーストのNoSQL、ScyllaDB(スキュラDB)
スケールアップファーストのNoSQL、ScyllaDB(スキュラDB)昌桓 李
 
The Next Generation Firewall for Red Hat Enterprise Linux 7 RC
The Next Generation Firewall for Red Hat Enterprise Linux 7 RCThe Next Generation Firewall for Red Hat Enterprise Linux 7 RC
The Next Generation Firewall for Red Hat Enterprise Linux 7 RCThomas Graf
 
YOW2021 Computing Performance
YOW2021 Computing PerformanceYOW2021 Computing Performance
YOW2021 Computing PerformanceBrendan Gregg
 
"SRv6の現状と展望" ENOG53@上越
"SRv6の現状と展望" ENOG53@上越"SRv6の現状と展望" ENOG53@上越
"SRv6の現状と展望" ENOG53@上越Kentaro Ebisawa
 
Linux BPF Superpowers
Linux BPF SuperpowersLinux BPF Superpowers
Linux BPF SuperpowersBrendan Gregg
 
Troubleshooting Native Memory Leaks in Java Applications
Troubleshooting Native Memory Leaks in Java ApplicationsTroubleshooting Native Memory Leaks in Java Applications
Troubleshooting Native Memory Leaks in Java ApplicationsPoonam Bajaj Parhar
 
データ爆発時代のネットワークインフラ
データ爆発時代のネットワークインフラデータ爆発時代のネットワークインフラ
データ爆発時代のネットワークインフラNVIDIA Japan
 
Poll mode driver integration into dpdk
Poll mode driver integration into dpdkPoll mode driver integration into dpdk
Poll mode driver integration into dpdkVipin Varghese
 
Open stack networking vlan, gre
Open stack networking   vlan, greOpen stack networking   vlan, gre
Open stack networking vlan, greSim Janghoon
 

What's hot (20)

BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and more
 
Delivering a new level of visual performance in an SoC AMD "Raven Ridge" APU
Delivering a new level of visual performance in an SoC AMD "Raven Ridge" APUDelivering a new level of visual performance in an SoC AMD "Raven Ridge" APU
Delivering a new level of visual performance in an SoC AMD "Raven Ridge" APU
 
仮想化専門コンサルタントが教える「成功する仮想化導入のポイント」
仮想化専門コンサルタントが教える「成功する仮想化導入のポイント」仮想化専門コンサルタントが教える「成功する仮想化導入のポイント」
仮想化専門コンサルタントが教える「成功する仮想化導入のポイント」
 
“Zen 3”: AMD 2nd Generation 7nm x86-64 Microprocessor Core
“Zen 3”: AMD 2nd Generation 7nm x86-64 Microprocessor Core“Zen 3”: AMD 2nd Generation 7nm x86-64 Microprocessor Core
“Zen 3”: AMD 2nd Generation 7nm x86-64 Microprocessor Core
 
LinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking WalkthroughLinuxCon 2015 Linux Kernel Networking Walkthrough
LinuxCon 2015 Linux Kernel Networking Walkthrough
 
데브옵스(DevOps)의 현재와 미래 - ChatOps & VoiceOps (윤석찬)
데브옵스(DevOps)의 현재와 미래 - ChatOps & VoiceOps (윤석찬)데브옵스(DevOps)의 현재와 미래 - ChatOps & VoiceOps (윤석찬)
데브옵스(DevOps)의 현재와 미래 - ChatOps & VoiceOps (윤석찬)
 
DPDK KNI interface
DPDK KNI interfaceDPDK KNI interface
DPDK KNI interface
 
Heterogeneous Systems Architecture: The Next Area of Computing Innovation
Heterogeneous Systems Architecture: The Next Area of Computing Innovation Heterogeneous Systems Architecture: The Next Area of Computing Innovation
Heterogeneous Systems Architecture: The Next Area of Computing Innovation
 
スケールアップファーストのNoSQL、ScyllaDB(スキュラDB)
スケールアップファーストのNoSQL、ScyllaDB(スキュラDB)スケールアップファーストのNoSQL、ScyllaDB(スキュラDB)
スケールアップファーストのNoSQL、ScyllaDB(スキュラDB)
 
Understanding DPDK
Understanding DPDKUnderstanding DPDK
Understanding DPDK
 
The Next Generation Firewall for Red Hat Enterprise Linux 7 RC
The Next Generation Firewall for Red Hat Enterprise Linux 7 RCThe Next Generation Firewall for Red Hat Enterprise Linux 7 RC
The Next Generation Firewall for Red Hat Enterprise Linux 7 RC
 
YOW2021 Computing Performance
YOW2021 Computing PerformanceYOW2021 Computing Performance
YOW2021 Computing Performance
 
"SRv6の現状と展望" ENOG53@上越
"SRv6の現状と展望" ENOG53@上越"SRv6の現状と展望" ENOG53@上越
"SRv6の現状と展望" ENOG53@上越
 
Linux BPF Superpowers
Linux BPF SuperpowersLinux BPF Superpowers
Linux BPF Superpowers
 
BGP Update Source
BGP Update Source BGP Update Source
BGP Update Source
 
Troubleshooting Native Memory Leaks in Java Applications
Troubleshooting Native Memory Leaks in Java ApplicationsTroubleshooting Native Memory Leaks in Java Applications
Troubleshooting Native Memory Leaks in Java Applications
 
GPU - Basic Working
GPU - Basic WorkingGPU - Basic Working
GPU - Basic Working
 
データ爆発時代のネットワークインフラ
データ爆発時代のネットワークインフラデータ爆発時代のネットワークインフラ
データ爆発時代のネットワークインフラ
 
Poll mode driver integration into dpdk
Poll mode driver integration into dpdkPoll mode driver integration into dpdk
Poll mode driver integration into dpdk
 
Open stack networking vlan, gre
Open stack networking   vlan, greOpen stack networking   vlan, gre
Open stack networking vlan, gre
 

Viewers also liked

Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway ichikaway
 
Experience of (Ichikaway iteigo1)
Experience of (Ichikaway iteigo1)Experience of (Ichikaway iteigo1)
Experience of (Ichikaway iteigo1)ichikaway
 
Road to CakePHP 3.0
Road to CakePHP 3.0Road to CakePHP 3.0
Road to CakePHP 3.0markstory
 
3.4 ict strategy
3.4 ict strategy3.4 ict strategy
3.4 ict strategymrmwood
 
The Business Case for Corporate Performance Management
The Business Case for Corporate Performance ManagementThe Business Case for Corporate Performance Management
The Business Case for Corporate Performance ManagementCharles Bedard
 
Cell project example
Cell project exampleCell project example
Cell project examplehappygirl1983
 
Leadership Sustainability: Seven Disciplines to Achieve the Changes Great Lea...
Leadership Sustainability: Seven Disciplines to Achieve the Changes Great Lea...Leadership Sustainability: Seven Disciplines to Achieve the Changes Great Lea...
Leadership Sustainability: Seven Disciplines to Achieve the Changes Great Lea...Human Capital Media
 
Satellite Videoconferencing
Satellite VideoconferencingSatellite Videoconferencing
Satellite Videoconferencingtech4101
 

Viewers also liked (13)

Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
 
Experience of (Ichikaway iteigo1)
Experience of (Ichikaway iteigo1)Experience of (Ichikaway iteigo1)
Experience of (Ichikaway iteigo1)
 
CakePHP 3
CakePHP 3CakePHP 3
CakePHP 3
 
Tài liệu HTML5-CSS3
Tài liệu HTML5-CSS3Tài liệu HTML5-CSS3
Tài liệu HTML5-CSS3
 
Road to CakePHP 3.0
Road to CakePHP 3.0Road to CakePHP 3.0
Road to CakePHP 3.0
 
Advanced Querying with CakePHP 3
Advanced Querying with CakePHP 3Advanced Querying with CakePHP 3
Advanced Querying with CakePHP 3
 
3.4 ict strategy
3.4 ict strategy3.4 ict strategy
3.4 ict strategy
 
The Business Case for Corporate Performance Management
The Business Case for Corporate Performance ManagementThe Business Case for Corporate Performance Management
The Business Case for Corporate Performance Management
 
2011-2012 Slumber Parties Catalog
2011-2012 Slumber Parties Catalog2011-2012 Slumber Parties Catalog
2011-2012 Slumber Parties Catalog
 
Biography= My grandmother
Biography= My grandmotherBiography= My grandmother
Biography= My grandmother
 
Cell project example
Cell project exampleCell project example
Cell project example
 
Leadership Sustainability: Seven Disciplines to Achieve the Changes Great Lea...
Leadership Sustainability: Seven Disciplines to Achieve the Changes Great Lea...Leadership Sustainability: Seven Disciplines to Achieve the Changes Great Lea...
Leadership Sustainability: Seven Disciplines to Achieve the Changes Great Lea...
 
Satellite Videoconferencing
Satellite VideoconferencingSatellite Videoconferencing
Satellite Videoconferencing
 

Similar to How to use MongoDB with CakePHP

MongoDB Pros and Cons
MongoDB Pros and ConsMongoDB Pros and Cons
MongoDB Pros and Consjohnrjenson
 
Back to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDBBack to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDBMongoDB
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDBNorberto Leite
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongoMichael Bright
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and PythonMike Bright
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlTO THE NEW | Technology
 
MongoDB at FrozenRails
MongoDB at FrozenRailsMongoDB at FrozenRails
MongoDB at FrozenRailsMike Dirolf
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBMongoDB
 
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBBedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBTobias Trelle
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBRavi Teja
 
Mongodb intro
Mongodb introMongodb intro
Mongodb introchristkv
 
Mongo db eveningschemadesign
Mongo db eveningschemadesignMongo db eveningschemadesign
Mongo db eveningschemadesignMongoDB APAC
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012sullis
 

Similar to How to use MongoDB with CakePHP (20)

MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB Pros and Cons
MongoDB Pros and ConsMongoDB Pros and Cons
MongoDB Pros and Cons
 
Back to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDBBack to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDB
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
MongoDB and Python
MongoDB and PythonMongoDB and Python
MongoDB and Python
 
Python and MongoDB
Python and MongoDB Python and MongoDB
Python and MongoDB
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and Python
 
Rails with mongodb
Rails with mongodbRails with mongodb
Rails with mongodb
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behl
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB at FrozenRails
MongoDB at FrozenRailsMongoDB at FrozenRails
MongoDB at FrozenRails
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDBBedCon 2013 - Java Persistenz-Frameworks für MongoDB
BedCon 2013 - Java Persistenz-Frameworks für MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
2012 phoenix mug
2012 phoenix mug2012 phoenix mug
2012 phoenix mug
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
Mongo db eveningschemadesign
Mongo db eveningschemadesignMongo db eveningschemadesign
Mongo db eveningschemadesign
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012
 
mongodb tutorial
mongodb tutorialmongodb tutorial
mongodb tutorial
 

More from ichikaway

forteeに脆弱性検査をかけてみた VAddy編
forteeに脆弱性検査をかけてみた VAddy編forteeに脆弱性検査をかけてみた VAddy編
forteeに脆弱性検査をかけてみた VAddy編ichikaway
 
Understanding Computer Architecture with NES Emulator
Understanding Computer Architecture with NES EmulatorUnderstanding Computer Architecture with NES Emulator
Understanding Computer Architecture with NES Emulatorichikaway
 
VAddyの課金システムを Stripeに乗り換えた話
VAddyの課金システムを Stripeに乗り換えた話VAddyの課金システムを Stripeに乗り換えた話
VAddyの課金システムを Stripeに乗り換えた話ichikaway
 
Hello, Worldまで3ヶ月 Golangでファミコンエミュレータ実装 #gocon fukuoka 2019
Hello, Worldまで3ヶ月 Golangでファミコンエミュレータ実装 #gocon fukuoka 2019Hello, Worldまで3ヶ月 Golangでファミコンエミュレータ実装 #gocon fukuoka 2019
Hello, Worldまで3ヶ月 Golangでファミコンエミュレータ実装 #gocon fukuoka 2019ichikaway
 
ゼロから始めるファミコンエミュレータ生活 PHPerKaigi2019
ゼロから始めるファミコンエミュレータ生活 PHPerKaigi2019ゼロから始めるファミコンエミュレータ生活 PHPerKaigi2019
ゼロから始めるファミコンエミュレータ生活 PHPerKaigi2019ichikaway
 
現場で使える脆弱性検査サービス VAddy
現場で使える脆弱性検査サービス VAddy 現場で使える脆弱性検査サービス VAddy
現場で使える脆弱性検査サービス VAddy ichikaway
 
OS入門 Fukuoka.php vol.18 LT資料
OS入門 Fukuoka.php vol.18 LT資料OS入門 Fukuoka.php vol.18 LT資料
OS入門 Fukuoka.php vol.18 LT資料ichikaway
 
Yapc8oji: セキュリティテストサービスを開発運営してきた2年
Yapc8oji: セキュリティテストサービスを開発運営してきた2年Yapc8oji: セキュリティテストサービスを開発運営してきた2年
Yapc8oji: セキュリティテストサービスを開発運営してきた2年ichikaway
 
VAaddyとは VAddyミートアップvol3_20160629
VAaddyとは  VAddyミートアップvol3_20160629VAaddyとは  VAddyミートアップvol3_20160629
VAaddyとは VAddyミートアップvol3_20160629ichikaway
 
脆弱性もバグ、だからテストしよう PHPカンファンレス2015
脆弱性もバグ、だからテストしよう PHPカンファンレス2015脆弱性もバグ、だからテストしよう PHPカンファンレス2015
脆弱性もバグ、だからテストしよう PHPカンファンレス2015ichikaway
 
脆弱性もバグ、だからテストしよう DevSummiFukuoka
脆弱性もバグ、だからテストしよう DevSummiFukuoka脆弱性もバグ、だからテストしよう DevSummiFukuoka
脆弱性もバグ、だからテストしよう DevSummiFukuokaichikaway
 
Vulnerabilities are bugs, Let's test for them!
Vulnerabilities are bugs, Let's test for them!Vulnerabilities are bugs, Let's test for them!
Vulnerabilities are bugs, Let's test for them!ichikaway
 
脆弱性もバグ、だからテストしよう!
脆弱性もバグ、だからテストしよう!脆弱性もバグ、だからテストしよう!
脆弱性もバグ、だからテストしよう!ichikaway
 
継続的Webセキュリティテスト PHPカンファレンス関西2015 LT
継続的Webセキュリティテスト PHPカンファレンス関西2015 LT継続的Webセキュリティテスト PHPカンファレンス関西2015 LT
継続的Webセキュリティテスト PHPカンファレンス関西2015 LTichikaway
 
継続的Webセキュリティテスト testing casual talks2
継続的Webセキュリティテスト testing casual talks2継続的Webセキュリティテスト testing casual talks2
継続的Webセキュリティテスト testing casual talks2ichikaway
 
Ctf2015 ichikawa Eizoku PM2.5 dial
Ctf2015 ichikawa Eizoku PM2.5 dialCtf2015 ichikawa Eizoku PM2.5 dial
Ctf2015 ichikawa Eizoku PM2.5 dialichikaway
 
VAddy - CI勉強会 fukuoka
VAddy - CI勉強会 fukuokaVAddy - CI勉強会 fukuoka
VAddy - CI勉強会 fukuokaichikaway
 
Jenkinsを使った継続的セキュリティテスト
Jenkinsを使った継続的セキュリティテストJenkinsを使った継続的セキュリティテスト
Jenkinsを使った継続的セキュリティテストichikaway
 
継続的セキュリティテストVaddy説明資料
継続的セキュリティテストVaddy説明資料継続的セキュリティテストVaddy説明資料
継続的セキュリティテストVaddy説明資料ichikaway
 
VAddy at LL Diver LT
VAddy at LL Diver LTVAddy at LL Diver LT
VAddy at LL Diver LTichikaway
 

More from ichikaway (20)

forteeに脆弱性検査をかけてみた VAddy編
forteeに脆弱性検査をかけてみた VAddy編forteeに脆弱性検査をかけてみた VAddy編
forteeに脆弱性検査をかけてみた VAddy編
 
Understanding Computer Architecture with NES Emulator
Understanding Computer Architecture with NES EmulatorUnderstanding Computer Architecture with NES Emulator
Understanding Computer Architecture with NES Emulator
 
VAddyの課金システムを Stripeに乗り換えた話
VAddyの課金システムを Stripeに乗り換えた話VAddyの課金システムを Stripeに乗り換えた話
VAddyの課金システムを Stripeに乗り換えた話
 
Hello, Worldまで3ヶ月 Golangでファミコンエミュレータ実装 #gocon fukuoka 2019
Hello, Worldまで3ヶ月 Golangでファミコンエミュレータ実装 #gocon fukuoka 2019Hello, Worldまで3ヶ月 Golangでファミコンエミュレータ実装 #gocon fukuoka 2019
Hello, Worldまで3ヶ月 Golangでファミコンエミュレータ実装 #gocon fukuoka 2019
 
ゼロから始めるファミコンエミュレータ生活 PHPerKaigi2019
ゼロから始めるファミコンエミュレータ生活 PHPerKaigi2019ゼロから始めるファミコンエミュレータ生活 PHPerKaigi2019
ゼロから始めるファミコンエミュレータ生活 PHPerKaigi2019
 
現場で使える脆弱性検査サービス VAddy
現場で使える脆弱性検査サービス VAddy 現場で使える脆弱性検査サービス VAddy
現場で使える脆弱性検査サービス VAddy
 
OS入門 Fukuoka.php vol.18 LT資料
OS入門 Fukuoka.php vol.18 LT資料OS入門 Fukuoka.php vol.18 LT資料
OS入門 Fukuoka.php vol.18 LT資料
 
Yapc8oji: セキュリティテストサービスを開発運営してきた2年
Yapc8oji: セキュリティテストサービスを開発運営してきた2年Yapc8oji: セキュリティテストサービスを開発運営してきた2年
Yapc8oji: セキュリティテストサービスを開発運営してきた2年
 
VAaddyとは VAddyミートアップvol3_20160629
VAaddyとは  VAddyミートアップvol3_20160629VAaddyとは  VAddyミートアップvol3_20160629
VAaddyとは VAddyミートアップvol3_20160629
 
脆弱性もバグ、だからテストしよう PHPカンファンレス2015
脆弱性もバグ、だからテストしよう PHPカンファンレス2015脆弱性もバグ、だからテストしよう PHPカンファンレス2015
脆弱性もバグ、だからテストしよう PHPカンファンレス2015
 
脆弱性もバグ、だからテストしよう DevSummiFukuoka
脆弱性もバグ、だからテストしよう DevSummiFukuoka脆弱性もバグ、だからテストしよう DevSummiFukuoka
脆弱性もバグ、だからテストしよう DevSummiFukuoka
 
Vulnerabilities are bugs, Let's test for them!
Vulnerabilities are bugs, Let's test for them!Vulnerabilities are bugs, Let's test for them!
Vulnerabilities are bugs, Let's test for them!
 
脆弱性もバグ、だからテストしよう!
脆弱性もバグ、だからテストしよう!脆弱性もバグ、だからテストしよう!
脆弱性もバグ、だからテストしよう!
 
継続的Webセキュリティテスト PHPカンファレンス関西2015 LT
継続的Webセキュリティテスト PHPカンファレンス関西2015 LT継続的Webセキュリティテスト PHPカンファレンス関西2015 LT
継続的Webセキュリティテスト PHPカンファレンス関西2015 LT
 
継続的Webセキュリティテスト testing casual talks2
継続的Webセキュリティテスト testing casual talks2継続的Webセキュリティテスト testing casual talks2
継続的Webセキュリティテスト testing casual talks2
 
Ctf2015 ichikawa Eizoku PM2.5 dial
Ctf2015 ichikawa Eizoku PM2.5 dialCtf2015 ichikawa Eizoku PM2.5 dial
Ctf2015 ichikawa Eizoku PM2.5 dial
 
VAddy - CI勉強会 fukuoka
VAddy - CI勉強会 fukuokaVAddy - CI勉強会 fukuoka
VAddy - CI勉強会 fukuoka
 
Jenkinsを使った継続的セキュリティテスト
Jenkinsを使った継続的セキュリティテストJenkinsを使った継続的セキュリティテスト
Jenkinsを使った継続的セキュリティテスト
 
継続的セキュリティテストVaddy説明資料
継続的セキュリティテストVaddy説明資料継続的セキュリティテストVaddy説明資料
継続的セキュリティテストVaddy説明資料
 
VAddy at LL Diver LT
VAddy at LL Diver LTVAddy at LL Diver LT
VAddy at LL Diver LT
 

Recently uploaded

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

How to use MongoDB with CakePHP

  • 1. How to use MongoDB with CakePHP 2010/9/4 Cakefest2010 Yasushi Ichikawa
  • 2. TOPIC 1. Who am I 2. MongoDB 3. PHP + MongoDB 4. CakePHP + MongoDB
  • 4. My Code • I've used Cakephp since Aug 2008. • Author of the SQL Explain Component → One of Debug_kit Contributors • Author of the Cakephp MongoDB-Datasource
  • 5. My Code  My code for Cakephp  http://github.com/ichikaway
  • 6. TOPIC 1. Who am I 2. MongoDB 3. PHP + MongoDB 4. CakePHP + MongoDB
  • 8. MongoDB • Open-source non-relational DB • C++ • GNU AGPL v3.0 • Many Drivers(PHP, Perl, Ruby, etc) – Apache License • Company: 10gen • Download (version 1.6.2) – http://www.mongodb.org/display/DOCS/Downloads
  • 9. MongoDB TERMs RDB MongoDB Table Collection Row Document Column Field
  • 10. MongoDB Position • Performance – Key/Value > mongoDB >>> RDBMS • Functionality – RDBMS > mongoDB >>> Key/Value
  • 11. MongoDB Provides • Scalability • Queryable • Read/Write FAST • Schema Free
  • 12. MongoDB Schema • Document: bson (similar json) – Binary data • Schema Free – different schema in same collection Id, title, body Id, name, tel, fax Id, name, nickname, email Posts collection
  • 13. MongoDB Schema • Embedded Object Posts collection id: 1, name: ichikaway, tel: 090-1111-2222. fax: Address skill Country: Japan, Java: 2years, Zip: 222-3333 PHP: 3years id: 2, name: Yasushi, tel: 090-3333-4444. fax: id: 3, name: Ninjaaa, tel: 090-5555-6666. fax:
  • 14. RDB Schema • RDB schema • Natural data structure?? Screen Blog Blog table Tags table Title Title Tag1 Text Text Tag2 Tag3 tag1,tag2,tag3 RDB Comment Table Comment1 Comment2 Comment1 Comment3 Comment2 Comment3
  • 15. MongoDB schema • Schema Free – Natural data structure Screen Blog Blog collection Title Title : xxxx Text Text : yyyy tag1,tag2,tag3 Mongo Tag: [tag1,tag2,tag3] Comment: [comment1, Comment1 comment2, Comment2 comment3 Comment3 ]
  • 16. MongoDB In Production github, heroku(MongoHQ), etc
  • 17. MongoDB Production Case • Business insider • http://www.businessinsider.com/how-we-use-mongodb-2009-11 • Over 600,000 PV / business day • 3 apache + 1 mongoDB • MongoDB uses under 5% cpu time
  • 18. MongoDB Fit or Not Not replace all RDBMS
  • 19. MongoDB Not FIT • Need Join • Need Transaction • Small disk space – each record has field label data Posts collection id: 1, name: ichikaway, tel: 090-1111-2222. fax: 6bytes id: 2, name: Yasushi, Age: 20 . Tel: 111-2222 id: 3, name: Ninjaaa, Language: Japanese
  • 20. MongoDB Fit • Need Performance – Read/Write is fast • Scale out – Master/Slave – Replica set(Automatic Failover) – Sharding
  • 22. MongoDB Retrieving Data SELECT field1, field2 From blog WHERE field1 = 'aaa'; db.blog.find( { field1 : ”aaa” }, { field1 : 1, field2 : 1 } ) Collection name
  • 23. MongoDB Retrieving Data SELECT * WHERE field1 > 3 ORDER BY field2 DESC LIMIT 10, 20; db.collection.find( { field1 : { $gt:3 } } ) .sort(field2: -1) .skip(10) .limit(20);
  • 24. MongoDB find operators • $gt, $gte • $lt, $lte • $ne • $in • $nin • $or http://www.mongodb.org/display/DOCS/Advanced+Queries
  • 25. MongoDB find tips • Regular Expressions – { name : /ichikawa.*sushi/i } • Embedded Object – { "author.name" : "ichikawa" } Blog collection Title : xxxx Text : yyyy author: { name : 'ichikawa', age : 15 }
  • 27. SQL to Mongo Mapping Chart http://www.mongodb.org/display/DOCS/SQL+to+Mongo+ Mapping+Chart
  • 28. MongoDB Indexing Create Index db.collection.ensureIndex({“title” : 1}) Delete Index db.collection.dropIndex({“title” : 1}) Create Embedded Doc Index db.collection.ensureIndex ({“Autor.name” : 1}) Create Index(Background) db.collection.ensureIndex ({“title” : 1}, {background:true} )
  • 29. Cool Stuffs of MongoDB Geospatial Index Capped Collection
  • 30. MongoDB Geospatial Index  Version 1.3.3+ , recommend 1.6.2+ (Bug fix)  Calculate location data – Latitude(緯度), Longitude(経度)  find the closest location with Operators – $near: sort from the closest point – $box: find points within the rectangle – $center: find points within the circle
  • 31. MongoDB Geospatial Index  Insert data db.geotest.save({ loc:[ 35, 139 ] }) Latitude Longitude  create Index db.geotest.ensureIndex( {loc:”2d”} )
  • 32. MongoDB Geospatial Index  Find the point db.geotest.find({ loc:[35, 140] });  $near db.geotest.find({ loc:{ $near : [30, 130] } })
  • 33. MongoDB Geospatial Index  $box – lower left, upper right db.geotest.find({ loc:{ $within:{ $box: [[1, 1], [10,10]] }}});  $center – set radius(degree) db.geotest.find({ loc:{ $within:{ $center: [[10, 10], 0.1 ] } radius(degree) }})
  • 35. MongoDB Capped Collection  Creating a Fixed Size (capped) Collection  Not think about data space / overflow • Age out data is deleted when Collection is full • Good for – Logging – Caching db.createCollection("testcap1", {capped: true, size:5000});
  • 36. MongoDB Attension  32bit version limitation –can't save data over 2Gbytes
  • 37. MongoDB Books http://www.mongodb.org/display/DOCS/Books
  • 38. TOPIC 1. Who am I 2. MongoDB 3. PHP + MongoDB 4. CakePHP + MongoDB
  • 39. Pecl Mongo Driver • Apache License • Setup pecl install mongo extension=mongo.so (php.ini) • Manual –http://us2.php.net/mongo
  • 40. Pecl Mongo • Connect $mongo = new Mongo(localhost:27017); $db = $mongo->selectDB('blog'); • select collection $collection = $db->selectCollection('posts'); • Find $collection->find($cond, $filed) ->sort()->limit(5)->skip();
  • 41. Pecl Mongo $data = array('field1' => 'val1', 'field2' => 'val2'); • Insert $collection->insert($data); • Update $new = array('$set' => array('field2' => 'aa')); $cond = array('field1' => 'val1'); $collection->update($cond, $new);
  • 42. TOPIC 1. Who am I 2. MongoDB 3. PHP + MongoDB 4. CakePHP + MongoDB
  • 43. MongoDB Datasource  Developed since Jan, 2010  PHP5+  Pecl Mongo  CakePHP1.2+ – Recommend Cake1.3
  • 44. MongoDB Datasource  Version 0.3 – set schema info to Model::schema – test cases  Version 0.4 – create schema info from Post data – show command log Huge Thanks AD7six
  • 45. Cake Datasource  The link between models and the source(DB)  Transparency – Use Mongo from Model methods – connect to MongoDB and use collection automatically
  • 46. Cake calls Datasource methods Model Method Datasource find() read() save() create() save() update() delete() delete()
  • 48. Setup  cd app/plugins  git clone http://github.com/ichikaway/mongoDB- Datasource.git mongodb  cd app/config  vi database.php
  • 49. database.php <?php class DATABASE_CONFIG { public $default = array( 'driver' => 'mongodb.mongodbSource', 'database' => 'cakemongo1', 'host' => 'localhost', 'port' => 27017, );
  • 50. Sample Cake Mongo DEMO Sample1
  • 52. Sample Cake Mongo part 2  Delete History  Main data is stored in MySQL  save deleted records in history table  search history records
  • 53. Sample Cake Mongo part 2 MySQL App Default Schema CakePHP Post table User table
  • 54. Sample Cake Mongo part 2  RDB way  copy schema(all table)
  • 55. Sample Cake Mongo part 2 MySQL App Default Schema CakePHP Post table User table 1. Delete Copy Schema Post table User table 2. save
  • 56. Sample Cake Mongo part 2  RDB way  copy schema(all table)  Hard to maintain both schema  serialize deleted record, save in history table  Hard to search in history table
  • 57. Sample Cake Mongo 2 Mongo Way
  • 58. Sample Cake Mongo part 2 MySQL App Default Schema CakePHP Post table User table 1. Delete MongoDB History Collection {'post' : Post record} 2. save {'user' : User record}
  • 60. Sample Cake Mongo 2  Good Fit Document Database – save different table records in one collection  Don't need prepare schema before Save  Search easily in History Collection
  • 61. Summary  MongoDB - Good case - Query - Geospatial Index - Capped Collection  PHP + MongoDB  CakePHP + MongoDB
  • 62. Thank you! Questions? Please, speak slowly :)