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

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
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
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
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
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
 
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
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
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
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

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
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
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...
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
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
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
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.
 
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...
 
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
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
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...
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 

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