SlideShare a Scribd company logo
1 of 53
+

    1
I am Sanjeev   Shrestha
               @sanjeevshrestha




                                  2
In these slides...
         NoSQL
           TYPES
     MongoDB
      INSTALLATION
PHP & MongoDB

                           3
Intended Audience

BEGINNERS



                      4
Challenges with   RDBMS
Assumes
WELL DEFINED data structure
data is DENSE and largely UNIFORM
PROPERTIES of data can be defined upfront
INTERRELATIONSHIP are well ESTABLISHED & SYSTEMATIC
INDEXES can be CONSISTENTLY DEFINED
May SNAP when data grows enormously


                                             But ...
                              that may not be TRUE

                                                       5
DATA is


                   Unstructured
               Does not make sense

         OW
DATA is GR    IN   G   at high   speed



                                         6
NoSQL?

No Rel / No SQL / Not Only SQL / NoSQL
                  Non RELATIONAL
          DISTRIBUTED DATASTORES
                   May NOT provide   ACID
            Not a Single Product or Technology
     Data Storage and Manipulation



                                                 7
NoSQL Storage Types

DOCUMENT STORE
               GRAPH
KEY-VALUE STORE
           TABULAR
        multivalue database
            object database
                rdf database
                  tuple store


                                8
9
MongoDB

 High PERFORMANCE
     CONSISTENT
  Fully
HORIZONTALLY scalable
  DOUMENT Oriented



                           10
Best Features of KEY-VALUE stores,
DOCUMENT database & RELATIONAL
              databases




                                       11
Why so   POPULAR?

                         EASY to USE
                       SIMPLER concepts
           EASY on ramp for NoSQL
Many DEV/OPERATIONAL things come inbuilt
        More AGILE than RDBMS
Less UPFRONT DESIGN needed than RDBMS
 SCALABLE schema and storage

                                           12
Built for   SPEED


      Built for SPEED (written in C++)
          Data serialized to BSON
Extensive use of MEMORY MAPPED Files
  PADS DISK SPACE around document




                                               13
Why   MongoDB?
HIGH AVAILABILITY
  JOURNALING
 REPLICATION
  SHARDING
  INDEXING
AGGREGATION
 MAP/REDUCE
                             14
Negatives of   MONGODB



         INDEXES are not flexible
REALTIME QUERIES may not be as fast as others
   Good enough only if queries are SIMPLE
       Not as MATURED as RDBMS




                                                15
16
MONGODB seems to be the leader. CASSANDRA stands close second.



                                                                 17
RDBMS VS MONGODB
STRUCTURE


RDBMS           MONGODB
DATABASE        DATABASE
TABLES          COLLECTIONS
COLUMNS         DOCUMENTS
ROWS            FIELDS




                               18
RDBMS VS MONGODB


RDBMS               MONGODB
STORED PROCEDURES   STORED JAVASCRIPT
DATABASE SCHEMA     SCHEMA FREE
SUPPORTS JOINS      NO JOINS




                                        19
Relational normalized   DATA




                               20
Document Database normalized   DATA




                                      21
MySQL to MongoDB

MySQL Term    MongoDB Term
Database      Database
Tables        Collection
Rows          BSON Document
Column        BSON Fields
Index         Index
Join          Embedding and Linking
Primary Key   _id field
Group by      Aggregation




                                      22
SQL to MONGO


SQL Statements                      Mongo Statements
CREATE DATABASE sqltest             use mongotest
USE sqltest                         implicit
CREATE TABLE table1 (a Number, b    db.createCollection('coll1');
Number)
ALTER TABLE table1 add …            implicit
INSERT INTO table1 values(100,22)   db.coll1.insert({'a':'100,'b':22});




                                                                          23
SQL to MONGO
SQL Statements                              Mongo Statements
SELECT * from table1                        db.coll1.find();
SELECT * from table1 where a=33             db.coll1.find({a:33});
SELECT a,b from table1 where a =44          db.coll1.find({a:44},{a:1,b:1});
SELECT * from table1 where b like '%abc%'   db.coll1.find({b:/abc/});
SELECT * from table1 where b like 'abc%'    db.coll1.find({b:/^abc/});
SELECT * from table1 where a>50             db.coll1.find({a:{$gt:50}});
SELECT * from table1 where a <40            db.coll1.find({a:{$lt:40}});
SELECT * from table1 where a<=40            db.coll1.find({a:{$lte:40}});
SELECT * from table1 where a =33 order by   db.coll1.find({a:33}).sort({name:1})
name
SELECT * from table1 where a=33 order by    db.coll1.find({a:33}).sort({name:-1})
name DESC
SELECT * from table1 LIMIT 1                db.coll1.findOne();

                                                                                    24
SQL to MONGO
SQL Statements                                 Mongo Statements
SELECT * from table1 where a=33 and b=100 db.coll1.find({a:33,b:100});

SELECT * from table1 LIMIT 100                 db.coll1.find().limit(100);
SELECT * from table1 where a =33 or a=45 or db.coll1.find({$or:[{a:33},{a:45},{a:50}]})
a=50
SELECT DISTINCT a from table1                  db.coll1.distinct('a');
SELECT count(*) from table1                    db.coll1.count();
SELECT count(*) from table1 where a=33         db.coll1.find({a:33}).count();
CREATE INDEX myindexname ON table1(a)          db.coll1.ensureIndex({a:1})
UPDATE table1 set a=44 where b=100             db.coll1.update({b:100},{$set:
                                               {a:44}},false,true);
DELETE from table1 where a=44                  db.coll1.remove({a:44});



                                                                                          25
INSTALLATION



          It is DEAD SIMPLE

           Refer to the following link
http://www.mongodb.org/display/DOCS/Quickstart/




                                                  26
Get started with   MongoDB

MONGO SHELL
$ mongo




                                       27
Listing   DATABASES
show dbs;




                                  28
Creating   DATABASE
use databasename
but DB is not created
DB is created only when you
create a collection




                                                    29
Creating a   COLLECTION
db.createCollection('articles')
No Definition required




                                                       30
Listing   COLLECTIONS
show collections




                                           31
Inserting       DOCUMENT
db.collection.insert(<json formatted data>);
e.g.
db.articles.insert({title:'This is test article',slug:'this-is-test-article',text:'This is test article
and it does not contain anything',count:10});




                                                                                                          32
Listing   DOCUMENTS
db.collection.find()




                                             33
Updating        DOCUMENTS
db.collection.update( criteria, objNew, upsert, multi )
Upsert = update data if exists, insert as new data if not
Multi = make multiple updates matching criteria
e.g.
 db.articles.update({count:20},{$set:{title:'This is second article',slug:'this-is-second-
art'}},true,false)




                                                                                             34
creating   INDEX
db.collection.ensureIndex(index);
eg.
db.articles.ensureIndex({title:1})




                                                        35
MONGODB-PHP   EXTENSION



     Available from PECL
shell> pecl install mongo




                                 36
Loading   MONGO EXTENSION in PHP




Add   extension=mongo.so to php.ini
Or any other file like mongo.ini but make sure it is loaded by php




                                                                     37
Is it   LOADED?
Check PHP information




                                          38
Creating a   CONNECTION




                          39
Selecting   DB & COLLECTION




                              40
Listing from a   COLLECTION




                              41
Adding   DOCUMENT




                    42
43
Updating a   DOCUMENT




                        44
45
Deleting a   DOCUMENT




                        46
Working with multiple   COLLECTIONS


         no JOINS
 Instead REFs are used
       TWO Types
MANUAL / DBREFs


                                      47
Manual   REFs




                48
DBREFs




         49
Listing Data from multiple   COLLECTION




                                          50
What   NEXT?

GRIDFS
MAP/REDUCE
MONGOCODE {stored javascript}
AGGREGATION
SHARDING
REPLICAS
                                               51
REFERENCES


http://php.net/mongo/
http://www.mongodb.org/display/DOCS/PHP+Language+Center




                                                          52
THANK YOU
     &

HAPPY CODING




               53

More Related Content

What's hot

Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisKnoldus Inc.
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisDvir Volk
 
Oracle12c Pluggable Database Hands On - TROUG 2014
Oracle12c Pluggable Database Hands On - TROUG 2014Oracle12c Pluggable Database Hands On - TROUG 2014
Oracle12c Pluggable Database Hands On - TROUG 2014Özgür Umut Vurgun
 
GOTO 2013: Why Zalando trusts in PostgreSQL
GOTO 2013: Why Zalando trusts in PostgreSQLGOTO 2013: Why Zalando trusts in PostgreSQL
GOTO 2013: Why Zalando trusts in PostgreSQLHenning Jacobs
 
15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performanceguest9912e5
 
A brief introduction to PostgreSQL
A brief introduction to PostgreSQLA brief introduction to PostgreSQL
A brief introduction to PostgreSQLVu Hung Nguyen
 
Mastering the MongoDB Shell
Mastering the MongoDB ShellMastering the MongoDB Shell
Mastering the MongoDB ShellMongoDB
 
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL databaseAn Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL databaseAli MasudianPour
 
CORS review
CORS reviewCORS review
CORS reviewEric Ahn
 
MongoDB 在盛大大数据量下的应用
MongoDB 在盛大大数据量下的应用MongoDB 在盛大大数据量下的应用
MongoDB 在盛大大数据量下的应用iammutex
 

What's hot (20)

Mysql
MysqlMysql
Mysql
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
JSOP in 60 seconds
JSOP in 60 secondsJSOP in 60 seconds
JSOP in 60 seconds
 
Mongodb replication
Mongodb replicationMongodb replication
Mongodb replication
 
Oracle12c Pluggable Database Hands On - TROUG 2014
Oracle12c Pluggable Database Hands On - TROUG 2014Oracle12c Pluggable Database Hands On - TROUG 2014
Oracle12c Pluggable Database Hands On - TROUG 2014
 
GOTO 2013: Why Zalando trusts in PostgreSQL
GOTO 2013: Why Zalando trusts in PostgreSQLGOTO 2013: Why Zalando trusts in PostgreSQL
GOTO 2013: Why Zalando trusts in PostgreSQL
 
9.4json
9.4json9.4json
9.4json
 
15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance
 
Fluentd and WebHDFS
Fluentd and WebHDFSFluentd and WebHDFS
Fluentd and WebHDFS
 
A brief introduction to PostgreSQL
A brief introduction to PostgreSQLA brief introduction to PostgreSQL
A brief introduction to PostgreSQL
 
PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
 
My sql administration
My sql administrationMy sql administration
My sql administration
 
Unqlite
UnqliteUnqlite
Unqlite
 
Mastering the MongoDB Shell
Mastering the MongoDB ShellMastering the MongoDB Shell
Mastering the MongoDB Shell
 
An Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL databaseAn Introduction to REDIS NoSQL database
An Introduction to REDIS NoSQL database
 
MongoDB-SESSION03
MongoDB-SESSION03MongoDB-SESSION03
MongoDB-SESSION03
 
CORS review
CORS reviewCORS review
CORS review
 
MongoDB 在盛大大数据量下的应用
MongoDB 在盛大大数据量下的应用MongoDB 在盛大大数据量下的应用
MongoDB 在盛大大数据量下的应用
 
Perl Programming - 04 Programming Database
Perl Programming - 04 Programming DatabasePerl Programming - 04 Programming Database
Perl Programming - 04 Programming Database
 

Viewers also liked

Mongo NYC PHP Development
Mongo NYC PHP Development Mongo NYC PHP Development
Mongo NYC PHP Development Fitz Agard
 
PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDBFitz Agard
 
Selva peruana principales lugares turisticos
Selva peruana principales lugares turisticosSelva peruana principales lugares turisticos
Selva peruana principales lugares turisticosAlan Bayona Manrique
 
Workplace Communication Generic
Workplace Communication GenericWorkplace Communication Generic
Workplace Communication GenericFitz Agard
 
Real time analytics using Hadoop and Elasticsearch
Real time analytics using Hadoop and ElasticsearchReal time analytics using Hadoop and Elasticsearch
Real time analytics using Hadoop and ElasticsearchAbhishek Andhavarapu
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsLinkedIn
 

Viewers also liked (6)

Mongo NYC PHP Development
Mongo NYC PHP Development Mongo NYC PHP Development
Mongo NYC PHP Development
 
PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDB
 
Selva peruana principales lugares turisticos
Selva peruana principales lugares turisticosSelva peruana principales lugares turisticos
Selva peruana principales lugares turisticos
 
Workplace Communication Generic
Workplace Communication GenericWorkplace Communication Generic
Workplace Communication Generic
 
Real time analytics using Hadoop and Elasticsearch
Real time analytics using Hadoop and ElasticsearchReal time analytics using Hadoop and Elasticsearch
Real time analytics using Hadoop and Elasticsearch
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Similar to MongoDB & PHP

Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Kai Zhao
 
MongoDB Knowledge share
MongoDB Knowledge shareMongoDB Knowledge share
MongoDB Knowledge shareMr Kyaing
 
Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptxSurya937648
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB Habilelabs
 
MySQL without the SQL -- Cascadia PHP
MySQL without the SQL -- Cascadia PHPMySQL without the SQL -- Cascadia PHP
MySQL without the SQL -- Cascadia PHPDave Stokes
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDoug Green
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBLee Theobald
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBNodeXperts
 
Mongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMohan Rathour
 
Next Top Data Model by Ian Plosker
Next Top Data Model by Ian PloskerNext Top Data Model by Ian Plosker
Next Top Data Model by Ian PloskerSyncConf
 
mongodb11 (1) (1).pptx
mongodb11 (1) (1).pptxmongodb11 (1) (1).pptx
mongodb11 (1) (1).pptxRoopaR36
 
DMDW Extra Lesson - NoSql and MongoDB
DMDW  Extra Lesson - NoSql and MongoDBDMDW  Extra Lesson - NoSql and MongoDB
DMDW Extra Lesson - NoSql and MongoDBJohannes Hoppe
 

Similar to MongoDB & PHP (20)

Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)Mongodb introduction and_internal(simple)
Mongodb introduction and_internal(simple)
 
MongoDB Knowledge share
MongoDB Knowledge shareMongoDB Knowledge share
MongoDB Knowledge share
 
Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptx
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
2012 phoenix mug
2012 phoenix mug2012 phoenix mug
2012 phoenix mug
 
lecture_34e.pptx
lecture_34e.pptxlecture_34e.pptx
lecture_34e.pptx
 
MongoDB
MongoDBMongoDB
MongoDB
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
MySQL without the SQL -- Cascadia PHP
MySQL without the SQL -- Cascadia PHPMySQL without the SQL -- Cascadia PHP
MySQL without the SQL -- Cascadia PHP
 
MongoDB-presentation.pptx
MongoDB-presentation.pptxMongoDB-presentation.pptx
MongoDB-presentation.pptx
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and Drupal
 
An Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDBAn Introduction To NoSQL & MongoDB
An Introduction To NoSQL & MongoDB
 
MongoDB
MongoDBMongoDB
MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Getting Started with MongoDB
Getting Started with MongoDBGetting Started with MongoDB
Getting Started with MongoDB
 
Mongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorial
 
Next Top Data Model by Ian Plosker
Next Top Data Model by Ian PloskerNext Top Data Model by Ian Plosker
Next Top Data Model by Ian Plosker
 
mongodb11 (1) (1).pptx
mongodb11 (1) (1).pptxmongodb11 (1) (1).pptx
mongodb11 (1) (1).pptx
 
MongoDB crud
MongoDB crudMongoDB crud
MongoDB crud
 
DMDW Extra Lesson - NoSql and MongoDB
DMDW  Extra Lesson - NoSql and MongoDBDMDW  Extra Lesson - NoSql and MongoDB
DMDW Extra Lesson - NoSql and MongoDB
 

Recently uploaded

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

MongoDB & PHP

  • 1. + 1
  • 2. I am Sanjeev Shrestha @sanjeevshrestha 2
  • 3. In these slides... NoSQL TYPES MongoDB INSTALLATION PHP & MongoDB 3
  • 5. Challenges with RDBMS Assumes WELL DEFINED data structure data is DENSE and largely UNIFORM PROPERTIES of data can be defined upfront INTERRELATIONSHIP are well ESTABLISHED & SYSTEMATIC INDEXES can be CONSISTENTLY DEFINED May SNAP when data grows enormously But ... that may not be TRUE 5
  • 6. DATA is Unstructured Does not make sense OW DATA is GR IN G at high speed 6
  • 7. NoSQL? No Rel / No SQL / Not Only SQL / NoSQL Non RELATIONAL DISTRIBUTED DATASTORES May NOT provide ACID Not a Single Product or Technology Data Storage and Manipulation 7
  • 8. NoSQL Storage Types DOCUMENT STORE GRAPH KEY-VALUE STORE TABULAR multivalue database object database rdf database tuple store 8
  • 9. 9
  • 10. MongoDB High PERFORMANCE CONSISTENT Fully HORIZONTALLY scalable DOUMENT Oriented 10
  • 11. Best Features of KEY-VALUE stores, DOCUMENT database & RELATIONAL databases 11
  • 12. Why so POPULAR? EASY to USE SIMPLER concepts EASY on ramp for NoSQL Many DEV/OPERATIONAL things come inbuilt More AGILE than RDBMS Less UPFRONT DESIGN needed than RDBMS SCALABLE schema and storage 12
  • 13. Built for SPEED Built for SPEED (written in C++) Data serialized to BSON Extensive use of MEMORY MAPPED Files PADS DISK SPACE around document 13
  • 14. Why MongoDB? HIGH AVAILABILITY JOURNALING REPLICATION SHARDING INDEXING AGGREGATION MAP/REDUCE 14
  • 15. Negatives of MONGODB INDEXES are not flexible REALTIME QUERIES may not be as fast as others Good enough only if queries are SIMPLE Not as MATURED as RDBMS 15
  • 16. 16
  • 17. MONGODB seems to be the leader. CASSANDRA stands close second. 17
  • 18. RDBMS VS MONGODB STRUCTURE RDBMS MONGODB DATABASE DATABASE TABLES COLLECTIONS COLUMNS DOCUMENTS ROWS FIELDS 18
  • 19. RDBMS VS MONGODB RDBMS MONGODB STORED PROCEDURES STORED JAVASCRIPT DATABASE SCHEMA SCHEMA FREE SUPPORTS JOINS NO JOINS 19
  • 22. MySQL to MongoDB MySQL Term MongoDB Term Database Database Tables Collection Rows BSON Document Column BSON Fields Index Index Join Embedding and Linking Primary Key _id field Group by Aggregation 22
  • 23. SQL to MONGO SQL Statements Mongo Statements CREATE DATABASE sqltest use mongotest USE sqltest implicit CREATE TABLE table1 (a Number, b db.createCollection('coll1'); Number) ALTER TABLE table1 add … implicit INSERT INTO table1 values(100,22) db.coll1.insert({'a':'100,'b':22}); 23
  • 24. SQL to MONGO SQL Statements Mongo Statements SELECT * from table1 db.coll1.find(); SELECT * from table1 where a=33 db.coll1.find({a:33}); SELECT a,b from table1 where a =44 db.coll1.find({a:44},{a:1,b:1}); SELECT * from table1 where b like '%abc%' db.coll1.find({b:/abc/}); SELECT * from table1 where b like 'abc%' db.coll1.find({b:/^abc/}); SELECT * from table1 where a>50 db.coll1.find({a:{$gt:50}}); SELECT * from table1 where a <40 db.coll1.find({a:{$lt:40}}); SELECT * from table1 where a<=40 db.coll1.find({a:{$lte:40}}); SELECT * from table1 where a =33 order by db.coll1.find({a:33}).sort({name:1}) name SELECT * from table1 where a=33 order by db.coll1.find({a:33}).sort({name:-1}) name DESC SELECT * from table1 LIMIT 1 db.coll1.findOne(); 24
  • 25. SQL to MONGO SQL Statements Mongo Statements SELECT * from table1 where a=33 and b=100 db.coll1.find({a:33,b:100}); SELECT * from table1 LIMIT 100 db.coll1.find().limit(100); SELECT * from table1 where a =33 or a=45 or db.coll1.find({$or:[{a:33},{a:45},{a:50}]}) a=50 SELECT DISTINCT a from table1 db.coll1.distinct('a'); SELECT count(*) from table1 db.coll1.count(); SELECT count(*) from table1 where a=33 db.coll1.find({a:33}).count(); CREATE INDEX myindexname ON table1(a) db.coll1.ensureIndex({a:1}) UPDATE table1 set a=44 where b=100 db.coll1.update({b:100},{$set: {a:44}},false,true); DELETE from table1 where a=44 db.coll1.remove({a:44}); 25
  • 26. INSTALLATION It is DEAD SIMPLE Refer to the following link http://www.mongodb.org/display/DOCS/Quickstart/ 26
  • 27. Get started with MongoDB MONGO SHELL $ mongo 27
  • 28. Listing DATABASES show dbs; 28
  • 29. Creating DATABASE use databasename but DB is not created DB is created only when you create a collection 29
  • 30. Creating a COLLECTION db.createCollection('articles') No Definition required 30
  • 31. Listing COLLECTIONS show collections 31
  • 32. Inserting DOCUMENT db.collection.insert(<json formatted data>); e.g. db.articles.insert({title:'This is test article',slug:'this-is-test-article',text:'This is test article and it does not contain anything',count:10}); 32
  • 33. Listing DOCUMENTS db.collection.find() 33
  • 34. Updating DOCUMENTS db.collection.update( criteria, objNew, upsert, multi ) Upsert = update data if exists, insert as new data if not Multi = make multiple updates matching criteria e.g. db.articles.update({count:20},{$set:{title:'This is second article',slug:'this-is-second- art'}},true,false) 34
  • 35. creating INDEX db.collection.ensureIndex(index); eg. db.articles.ensureIndex({title:1}) 35
  • 36. MONGODB-PHP EXTENSION Available from PECL shell> pecl install mongo 36
  • 37. Loading MONGO EXTENSION in PHP Add extension=mongo.so to php.ini Or any other file like mongo.ini but make sure it is loaded by php 37
  • 38. Is it LOADED? Check PHP information 38
  • 39. Creating a CONNECTION 39
  • 40. Selecting DB & COLLECTION 40
  • 41. Listing from a COLLECTION 41
  • 42. Adding DOCUMENT 42
  • 43. 43
  • 44. Updating a DOCUMENT 44
  • 45. 45
  • 46. Deleting a DOCUMENT 46
  • 47. Working with multiple COLLECTIONS no JOINS Instead REFs are used TWO Types MANUAL / DBREFs 47
  • 48. Manual REFs 48
  • 49. DBREFs 49
  • 50. Listing Data from multiple COLLECTION 50
  • 51. What NEXT? GRIDFS MAP/REDUCE MONGOCODE {stored javascript} AGGREGATION SHARDING REPLICAS 51
  • 53. THANK YOU & HAPPY CODING 53