SlideShare a Scribd company logo
1 of 18
Thanasis Efthymiou
Service Delivery Manager




                           Introduction to



                            Athens MongoDB User group
Thanasis Efthymiou,




                       But wait!




              What’s our group all about?
                                            2
Thanasis Efthymiou,




                      What we want is to:
   • Explore MongoDB and related technologies
         – “NoSQL” design culture
         – Map/Reduce
         – Hadoop, Hive, …
   • Learn from each other while having fun
   • Connect with the experts (and become one)
   • Free coffee

                                                 3
Thanasis Efthymiou,




                      Our Sponsors




                                     4
Thanasis Efthymiou,




              So what is                                                                   ?
   • Open-source database
         – Free to download and use
         – Subscription services for support offered by 10gen
   • Document-oriented database
         –   Fields, documents and collections instead of columns, rows and tables as in RDBMS
         –   Flexible and dynamic schema, no predefined or rigid as in RDBMS
         –   JSON documents, e.g.: {field1 : value1, field2 : value2 }
         –   Possibility to embed documents within others, e.g.: {f1 : v1, f2 : { f3: v3, f4: v4 } }
   • Built for scalability and high availability
         – Replica sets with automatic failover for redundancy
         – Auto-sharding for performance and load balancing
         – Built for the web, built to live in the fluffy clouds
   • Rich query interface
         – Javascript-powered shell
   • Easy to setup and administer
                                                                                                       5
Thanasis Efthymiou,




                      Replica set sneak peek




                                               6
Thanasis Efthymiou,




                      Sharding sneak peek




                                            7
Thanasis Efthymiou,




              So what is                                                        ?
                           SQL world                  MongoDB
                           Database                    Database
                             Table                     Collection
                             Index                       Index
                             Row                      Document
                            Column                       Field
                            Joining               Embedding & linking

                                      JSON document examples
     • {a:1}
     • { b : 2, c : "Hello world!", d : new Date('Jan 16, 2013')}
     • {        name                 :         "Thanasis",
                'company'            :         "Persado",
                "address"            :         "Kastorias 4, 15344, Gerakas",
                likes                :         ["photography", "cycling"],
                drinksCoffee         :         true      }
                                                                                    8
Thanasis Efthymiou,




              So what is                                                      ?
                                                                               GROUP BY
   • Map/Reduce                                     SELECT and
                                                                                clause
         – Map: transform and filter data          WHERE clause
         – Reduce: combine multiple rows into fewer records, i.e. aggregate
   • Hadoop connector
         – If you have really, really huge data sets
   • Capped collections
         – Guarantee preservation of the insertion order
         – Guarantee insertion order is identical to the order on disk
         – Powerful for logging
   • GridFS
         – Storing/retrieving files exceeding the 16MB document size limit (e.g. video)
         – Divides a file into parts, or chunks and stores them as separate documents

                                                                                          9
Thanasis Efthymiou,




              So what is                                                              ?
   • It goes…
         – Said to be 2 to 10 times faster than MySQL, depending on the “write concern”
               • Fire and forget versus wait for acknowledgement from n servers
         – Designed to be shared across multiple machines
         – In-place updates (typical example the incremental operator $inc)
         – Typically makes use of commodity servers with enough RAM to keep the entire data set
           in memory
   • Great index support
         – Pretty similar concepts apply as in RDBMS
         – Take it easy on the indexes, your write operations might slow down
         – The query optimizer selects the index empirically by occasionally running alternate
           query plans and by selecting the plan with the best response time
         – Can be unique, compound, multikey indexes on arrays, sparse
         – Can be created in a non-blocking fashion in the background
         – And the mobile web’s favorite…

                                                                                                  10
Thanasis Efthymiou,

                              Geospatial index example
           Create it: db.places.ensureIndex( {coord : '2d'} )
           Use it: db.places.find( { coord: {$near : [38.008003, 23.865303] } } )




                                                                                    11
Thanasis Efthymiou,




                                                          is not…
   • SQL RDBMS like Oracle, MySQL or SQL Server
         –   No SQL supported but does have rich query syntax
         –   No transactions (and no commit necessary!)
         –   No referential integrity of data, no foreign keys, no constraints, no triggers!
         –   No joins!
   • What? No joins??
         – Go for embedded documents or
         – Emulate joining in your application (multiple queries using code)
   • No stored procedures or views, but stored Javascript
   • No tabular interface / data grid looks
         – No Toad or SQL Developer clients
         – No easy data copy-paste to Excel
   • No Alter Table commands that can take minutes or hours
                                                                                               12
Thanasis Efthymiou,




               Querying
   >db.people.insert( {name:"Thanasis",'company':"Persado","address":"Kastorias 4, 15344,
   Gerakas",likes:["photography", "cycling"],drinksCoffee:true} )
   >
   >db.people.find()
   { "_id" : ObjectId("50f57146fcb8b36343367b8f"), "name" : "Thanasis", "company" : "Persado",
   "address" : "Kastorias 4, 15344, Gerakas", "likes" : [ "photography", "cycling" ], "drinksCoffee" :
   true }
   >db.people.find().pretty()
   {
       "_id" : ObjectId("50f57146fcb8b36343367b8f"),
       "name" : "Thanasis",
       "company" : "Persado",
       "address" : "Kastorias 4, 15344, Gerakas",
       "likes" : [
            "photography",
            "cycling"
       ],
       "drinksCoffee" : true
   }                                                                                                     13
Thanasis Efthymiou,




                   Querying
    >db.people.find( … )

{ a: 10 }                        a is 10, or an array containing the value 10
{ a: 10, b: “hello” }            a is 10 and b is “hello”
{ a: {$gt: 10} }                 a is greater than 10. Also $lt (<), $gte (>=), $lte (<=), and $ne (!=)
{ a: {$in: [10, “hello”]} }      a is either 10 or “hello”
{ a: {$all: [10, “hello”]} }     a is an array containing both 10 and “hello”
{ “a.b”: 10 }                    a is an embedded document with b equal to 10
                                  a is an array containing a single item with both b equal to 1 and c equal
{ a: {$elemMatch: {b: 1, c: 2}} } to 2
{ $or: [{a: 1}, {b: 2}] }        a is 1 or b is 2
{ a: /^m/ }                      a begins with the letter “m”


                                                                                                          14
Thanasis Efthymiou,




               Updating
    >db.people.update( query, update, <upsert>, <multi> )
    >db.people.update({company:"Upstream"}, {$set:{company:"Persado"}},
                                                            false, true)
    >db.people.update({company:"Upstream"}, {company:"Persado"})
{ $inc: {a: 2} }                      Increment a by 2
{ $set: {a: 5} }                      Set a to the value 5
{ $unset: {a: 1} }                    Delete the a key
{ $push: {a: 1} }                     Append the value 1 to the array a
{ $pushAll: {a: [1, 2]} }             Append both 1 and 2 to the array a
{ $addToSet: {a: 1} }                 Append the value 1 to the array a (if it doesn’t already exist)
{ $addToSet: {a: {$each: [1, 2]}} }   Append both 1 and 2 to the array a (if they don’t already exist)
{ $pop: {a: 1} }                      Remove the last element from the array a
{ $pop: {a: -1} }                     Remove the first element from the array a
{ $pull: {a: 5} }                     Remove all occurrences of 5 from the array a
{ $pullAll: {a: [5, 6]} }             Remove all occurrences of 5 or 6 from the array a
                                                                                                         15
Thanasis Efthymiou,




           SQL versus
                      SQL                                        MongoDB
  SELECT * FROM users                      db.users.find()

  INSERT INTO users VALUES ('Bob', 32)     db.users.insert({name: "Bob", age: 32})
  SELECT name, age FROM users
  WHERE age = 33                           db.users.find({age: 33}, {name: 1, age: 1, _id:0})
  SELECT * FROM users WHERE age = 33
  ORDER BY name ASC                        db.users.find({age: 33}).sort({name: 1})

  SELECT * FROM users WHERE age > 33       db.users.find({age: {$gt: 33}})
  SELECT * FROM users
  WHERE name LIKE '%Joe%'                  db.users.find({name: /Joe/})
  SELECT COUNT(*) FROM users
  WHERE AGE > 30                           db.users.find({age: {$gt: 30}}).count()
  UPDATE users SET age = 33 WHERE name =   db.users.update({name: "Bob"}, {$set: {age: 33}}, false,
  'Bob'                                    true)

  DELETE FROM users WHERE name = 'Bob'     db.users.remove({name: "Bob"})
                                                                                                      16
Thanasis Efthymiou,




                                Find out more!

           Download and documentation             http://www.mongodb.org/

           Use cases, training, everything        http://www.10gen.com/

           Online training portal – don’t miss!   https://education.10gen.com/

           API and drivers                        http://api.mongodb.org/

           If you’re still hard to satisfy        http://www.google.com




                                                                                 17
Thanasis Efthymiou,




                             Thank you!
                      http://www.meetup.com/Athens-MongoDB/
                      Don’t forget to RSVP Yes to our Events!


                      thanasis.efthymiou@gmail.com


                      www.facebook.com/MongoDBGreece


                      www.linkedin.com/groups/MongoDB-Greece-4731560


                                                                       18

More Related Content

Viewers also liked

Getting Started with MongoDB
Getting Started with MongoDBGetting Started with MongoDB
Getting Started with MongoDBPankaj Bajaj
 
Seth Edwards on MongoDB
Seth Edwards on MongoDBSeth Edwards on MongoDB
Seth Edwards on MongoDBSkills Matter
 
Mongodb intro
Mongodb introMongodb intro
Mongodb introchristkv
 
Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)MongoSF
 
An Evening with MongoDB - Orlando: Welcome and Keynote
An Evening with MongoDB - Orlando: Welcome and KeynoteAn Evening with MongoDB - Orlando: Welcome and Keynote
An Evening with MongoDB - Orlando: Welcome and KeynoteMongoDB
 
Zero to Mongo in 60 Hours
Zero to Mongo in 60 HoursZero to Mongo in 60 Hours
Zero to Mongo in 60 HoursMongoSF
 
Mongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdamsMongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdamsJAX London
 
Text databases and information retrieval
Text databases and information retrievalText databases and information retrieval
Text databases and information retrievalunyil96
 
MongoDB 3.2 Feature Preview
MongoDB 3.2 Feature PreviewMongoDB 3.2 Feature Preview
MongoDB 3.2 Feature PreviewNorberto Leite
 
MongoDB: Intro & Application for Big Data
MongoDB: Intro & Application  for Big DataMongoDB: Intro & Application  for Big Data
MongoDB: Intro & Application for Big DataTakahiro Inoue
 
MongoDB Introduction - Document Oriented Nosql Database
MongoDB Introduction - Document Oriented Nosql DatabaseMongoDB Introduction - Document Oriented Nosql Database
MongoDB Introduction - Document Oriented Nosql DatabaseSudhir Patil
 

Viewers also liked (19)

Getting Started with MongoDB
Getting Started with MongoDBGetting Started with MongoDB
Getting Started with MongoDB
 
Seth Edwards on MongoDB
Seth Edwards on MongoDBSeth Edwards on MongoDB
Seth Edwards on MongoDB
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)
 
An Evening with MongoDB - Orlando: Welcome and Keynote
An Evening with MongoDB - Orlando: Welcome and KeynoteAn Evening with MongoDB - Orlando: Welcome and Keynote
An Evening with MongoDB - Orlando: Welcome and Keynote
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongoDB 3.0
MongoDB 3.0 MongoDB 3.0
MongoDB 3.0
 
Plan de entrenamiento Maratón de Madrid Mes 3
Plan de entrenamiento Maratón de Madrid Mes 3Plan de entrenamiento Maratón de Madrid Mes 3
Plan de entrenamiento Maratón de Madrid Mes 3
 
Mongo db intro new
Mongo db intro newMongo db intro new
Mongo db intro new
 
Zero to Mongo in 60 Hours
Zero to Mongo in 60 HoursZero to Mongo in 60 Hours
Zero to Mongo in 60 Hours
 
Mongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdamsMongo DB on the JVM - Brendan McAdams
Mongo DB on the JVM - Brendan McAdams
 
Text databases and information retrieval
Text databases and information retrievalText databases and information retrieval
Text databases and information retrieval
 
MongoDB 3.2 Feature Preview
MongoDB 3.2 Feature PreviewMongoDB 3.2 Feature Preview
MongoDB 3.2 Feature Preview
 
Mongodb
MongodbMongodb
Mongodb
 
Mongodb
MongodbMongodb
Mongodb
 
MongoDB
MongoDBMongoDB
MongoDB
 
A Brief MongoDB Intro
A Brief MongoDB IntroA Brief MongoDB Intro
A Brief MongoDB Intro
 
MongoDB: Intro & Application for Big Data
MongoDB: Intro & Application  for Big DataMongoDB: Intro & Application  for Big Data
MongoDB: Intro & Application for Big Data
 
MongoDB Introduction - Document Oriented Nosql Database
MongoDB Introduction - Document Oriented Nosql DatabaseMongoDB Introduction - Document Oriented Nosql Database
MongoDB Introduction - Document Oriented Nosql Database
 

Recently uploaded

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
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
 

Recently uploaded (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
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.
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
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
 

Intro to MongoDB by Thanasis Efthymiou, Athens MongoDB User Group

  • 1. Thanasis Efthymiou Service Delivery Manager Introduction to Athens MongoDB User group
  • 2. Thanasis Efthymiou, But wait! What’s our group all about? 2
  • 3. Thanasis Efthymiou, What we want is to: • Explore MongoDB and related technologies – “NoSQL” design culture – Map/Reduce – Hadoop, Hive, … • Learn from each other while having fun • Connect with the experts (and become one) • Free coffee 3
  • 4. Thanasis Efthymiou, Our Sponsors 4
  • 5. Thanasis Efthymiou, So what is ? • Open-source database – Free to download and use – Subscription services for support offered by 10gen • Document-oriented database – Fields, documents and collections instead of columns, rows and tables as in RDBMS – Flexible and dynamic schema, no predefined or rigid as in RDBMS – JSON documents, e.g.: {field1 : value1, field2 : value2 } – Possibility to embed documents within others, e.g.: {f1 : v1, f2 : { f3: v3, f4: v4 } } • Built for scalability and high availability – Replica sets with automatic failover for redundancy – Auto-sharding for performance and load balancing – Built for the web, built to live in the fluffy clouds • Rich query interface – Javascript-powered shell • Easy to setup and administer 5
  • 6. Thanasis Efthymiou, Replica set sneak peek 6
  • 7. Thanasis Efthymiou, Sharding sneak peek 7
  • 8. Thanasis Efthymiou, So what is ? SQL world MongoDB Database Database Table Collection Index Index Row Document Column Field Joining Embedding & linking JSON document examples • {a:1} • { b : 2, c : "Hello world!", d : new Date('Jan 16, 2013')} • { name : "Thanasis", 'company' : "Persado", "address" : "Kastorias 4, 15344, Gerakas", likes : ["photography", "cycling"], drinksCoffee : true } 8
  • 9. Thanasis Efthymiou, So what is ? GROUP BY • Map/Reduce SELECT and clause – Map: transform and filter data WHERE clause – Reduce: combine multiple rows into fewer records, i.e. aggregate • Hadoop connector – If you have really, really huge data sets • Capped collections – Guarantee preservation of the insertion order – Guarantee insertion order is identical to the order on disk – Powerful for logging • GridFS – Storing/retrieving files exceeding the 16MB document size limit (e.g. video) – Divides a file into parts, or chunks and stores them as separate documents 9
  • 10. Thanasis Efthymiou, So what is ? • It goes… – Said to be 2 to 10 times faster than MySQL, depending on the “write concern” • Fire and forget versus wait for acknowledgement from n servers – Designed to be shared across multiple machines – In-place updates (typical example the incremental operator $inc) – Typically makes use of commodity servers with enough RAM to keep the entire data set in memory • Great index support – Pretty similar concepts apply as in RDBMS – Take it easy on the indexes, your write operations might slow down – The query optimizer selects the index empirically by occasionally running alternate query plans and by selecting the plan with the best response time – Can be unique, compound, multikey indexes on arrays, sparse – Can be created in a non-blocking fashion in the background – And the mobile web’s favorite… 10
  • 11. Thanasis Efthymiou, Geospatial index example Create it: db.places.ensureIndex( {coord : '2d'} ) Use it: db.places.find( { coord: {$near : [38.008003, 23.865303] } } ) 11
  • 12. Thanasis Efthymiou, is not… • SQL RDBMS like Oracle, MySQL or SQL Server – No SQL supported but does have rich query syntax – No transactions (and no commit necessary!) – No referential integrity of data, no foreign keys, no constraints, no triggers! – No joins! • What? No joins?? – Go for embedded documents or – Emulate joining in your application (multiple queries using code) • No stored procedures or views, but stored Javascript • No tabular interface / data grid looks – No Toad or SQL Developer clients – No easy data copy-paste to Excel • No Alter Table commands that can take minutes or hours 12
  • 13. Thanasis Efthymiou, Querying >db.people.insert( {name:"Thanasis",'company':"Persado","address":"Kastorias 4, 15344, Gerakas",likes:["photography", "cycling"],drinksCoffee:true} ) > >db.people.find() { "_id" : ObjectId("50f57146fcb8b36343367b8f"), "name" : "Thanasis", "company" : "Persado", "address" : "Kastorias 4, 15344, Gerakas", "likes" : [ "photography", "cycling" ], "drinksCoffee" : true } >db.people.find().pretty() { "_id" : ObjectId("50f57146fcb8b36343367b8f"), "name" : "Thanasis", "company" : "Persado", "address" : "Kastorias 4, 15344, Gerakas", "likes" : [ "photography", "cycling" ], "drinksCoffee" : true } 13
  • 14. Thanasis Efthymiou, Querying >db.people.find( … ) { a: 10 } a is 10, or an array containing the value 10 { a: 10, b: “hello” } a is 10 and b is “hello” { a: {$gt: 10} } a is greater than 10. Also $lt (<), $gte (>=), $lte (<=), and $ne (!=) { a: {$in: [10, “hello”]} } a is either 10 or “hello” { a: {$all: [10, “hello”]} } a is an array containing both 10 and “hello” { “a.b”: 10 } a is an embedded document with b equal to 10 a is an array containing a single item with both b equal to 1 and c equal { a: {$elemMatch: {b: 1, c: 2}} } to 2 { $or: [{a: 1}, {b: 2}] } a is 1 or b is 2 { a: /^m/ } a begins with the letter “m” 14
  • 15. Thanasis Efthymiou, Updating >db.people.update( query, update, <upsert>, <multi> ) >db.people.update({company:"Upstream"}, {$set:{company:"Persado"}}, false, true) >db.people.update({company:"Upstream"}, {company:"Persado"}) { $inc: {a: 2} } Increment a by 2 { $set: {a: 5} } Set a to the value 5 { $unset: {a: 1} } Delete the a key { $push: {a: 1} } Append the value 1 to the array a { $pushAll: {a: [1, 2]} } Append both 1 and 2 to the array a { $addToSet: {a: 1} } Append the value 1 to the array a (if it doesn’t already exist) { $addToSet: {a: {$each: [1, 2]}} } Append both 1 and 2 to the array a (if they don’t already exist) { $pop: {a: 1} } Remove the last element from the array a { $pop: {a: -1} } Remove the first element from the array a { $pull: {a: 5} } Remove all occurrences of 5 from the array a { $pullAll: {a: [5, 6]} } Remove all occurrences of 5 or 6 from the array a 15
  • 16. Thanasis Efthymiou, SQL versus SQL MongoDB SELECT * FROM users db.users.find() INSERT INTO users VALUES ('Bob', 32) db.users.insert({name: "Bob", age: 32}) SELECT name, age FROM users WHERE age = 33 db.users.find({age: 33}, {name: 1, age: 1, _id:0}) SELECT * FROM users WHERE age = 33 ORDER BY name ASC db.users.find({age: 33}).sort({name: 1}) SELECT * FROM users WHERE age > 33 db.users.find({age: {$gt: 33}}) SELECT * FROM users WHERE name LIKE '%Joe%' db.users.find({name: /Joe/}) SELECT COUNT(*) FROM users WHERE AGE > 30 db.users.find({age: {$gt: 30}}).count() UPDATE users SET age = 33 WHERE name = db.users.update({name: "Bob"}, {$set: {age: 33}}, false, 'Bob' true) DELETE FROM users WHERE name = 'Bob' db.users.remove({name: "Bob"}) 16
  • 17. Thanasis Efthymiou, Find out more! Download and documentation http://www.mongodb.org/ Use cases, training, everything http://www.10gen.com/ Online training portal – don’t miss! https://education.10gen.com/ API and drivers http://api.mongodb.org/ If you’re still hard to satisfy http://www.google.com 17
  • 18. Thanasis Efthymiou, Thank you! http://www.meetup.com/Athens-MongoDB/ Don’t forget to RSVP Yes to our Events! thanasis.efthymiou@gmail.com www.facebook.com/MongoDBGreece www.linkedin.com/groups/MongoDB-Greece-4731560 18