SlideShare una empresa de Scribd logo
1 de 29
Descargar para leer sin conexión
A gentle, friendly overview


       Antonio Pintus


        CRS4, 08/09/2011

               1
NOSQL /1

• MongoDB     belongs to the NoSQL databases family:

   • non-relational

   • document-oriented

   • no   prefixed, rigid, database schemas

   • no   joins

   • horizontal   scalability
                                2
NOSQL /2

• NoSQL    DB family includes several DB types:



 • document/oriented:     mongoDB, CouchDB, ...

 • Key Value   / Tuple Store: Redis, ...

 • Graph   databases: Neo4j, ...

 • ...
                                3
MongoDB

• Performant: C++                 • document-based      queries

• Schema-free                     • Map/Reduce

• Full   index support            • GridFS

• No     transactions             •a   JavaScript interactive shell

• Scalable: replication   +
 sharding

                              4
SCHEMA-FREE
• Schema-free    collections = NO TABLES!

•A   Mongo deployment (server) holds a set of databases

 •A   database holds a set of collections

     •A   collection holds a set of documents

      •A    document is a set of fields: key-value pair (BSON)

      •A     key is a name (string), a value is a basic type like
          string, integer, float, timestamp, binary, etc.,a document,
          or an array of values
                                   5
DATA FORMAT

• document/oriented

• stores   JSON-style documents: BSON (Binary JSON):

      • JSON       + other data types. E.g., Date type and a BinData
           type.

      • Can    reference other documents

• lightweight, traversable, efficient
                                    6
BSON
{!   "_id" : ObjectId("4dcec9a0af391a0d53000003"),


!    "servicetype" : "sensor",


!    "description" : "it’s only rock’n’roll but I like it",


!    "policy" : "PUBLIC",


!    "owner" : "User001",


!    "date_created" : "2011-05-02 17:11:28.874086",


!    "shortname" : "SampleSensor",


!    "content-type" : "text/plain",


!    "icon" : "http://myserver.com/images/sens.png"


}                                     7
COLLECTIONS

• More   or less, same concept as “table” but dynamic, schema-
 free



• collection   of BSON documents



• documents can have heterogeneous data structure in the
 same collection
                                8
QUERIES
• query    by documents

• Examples     (using the interactive shell):
    •   db.mycollection.find( {"policy" : "PUBLIC"} );


    •   db.mycollection.findOne({"policy" : "PUBLIC", “owner”:”User001”});


    •   db.mycollection.find({"policy" : "PUBLIC", “owner”:”User001”}).limit(2);


    •   db.mycollection.find( {"policy" : "PUBLIC"}, {“shortname”:1} );


    •   db.mycollection.find({"counter": {$gt:2}});


• conditional    ops: <,   <=, >, >=, $and, $in, $or,
  $nor, ...
                                        9
INDEXES
• Full   index support: index on any attribute (including multiple)

• increase    query performance

• indexes     are implemented as “B-Tree” indexes

• data    overhead for inserts and deletes, don’t abuse!
    •    db.mycollection.ensureIndex( {"servicetype" : 1} );


    •    db.mycollection.ensureIndex( {"servicetype" : 1, “owner”:-1} );


    •    db.mycollection.getIndexes()


    •    db.system.indexes.find()
                                         10
INSERTS

• Simplicity




•   db.mycollection.insert({“a”:”abc”,...})



•   var doc = {“name”:”mongodb”,...};

•   db.mycollection.insert(doc);

                            11
UPDATES
1. replace entire document

2. atomic, in-place updates
•   db.collection.update( criteria, objNew, upsert, multi )

        •   criteria: the query

        •   objNew: updated object or $ operators (e.g., $inc, $set) which manipulate the object

        •   upsert: if the record(s) do not exist, insert one.

        •   multi: if all documents matching criteria should be updated


•   db.collection.save(...): single object update with upsert
                                                   12
UPDATES /2

• atomic, in-place      updates = highly efficient

• provides     special operators
•   db.mycollection.update( { “shortname”:"Arduino" }, { $inc: { n : 1 } } );


•   db.mycollection.update( { “shortname”:"Arduino" }, { $set: { “shortname” :
    “OldArduino” } } );


• other    atomic ops: $unset,      $push, $pushAll, $addToSet, $pop,
    $pull, $rename, ...



                                         13
Mongo DISTRIBUTION
• Mac, Linux, Solaris, Win

• mongod: database         server.

      •   By default, port=27017, store path=/data/db.

      •   Override with --dbpath, --port command options




• mongo: interactive       JavaScript shell

• mongos: sharding        controller server
                                      14
MISCELLANEOUS: REST
• mongod      provides a basic REST interface

• launch    it with --rest option:        default port=28017


•   http://localhost:28017/mydb/mycollection/

•   http://localhost:28017/mydb/mycollection/?filter_shortname=Arduino

•   http://localhost:28017/mydb/mycollection/?filter_shortname=Arduino

•   http://localhost:28017/mydb/mycollection/?
    filter_shortname=Arduino&limit=10
                                     15
GOOD FOR

• event   logging

• high   performance small read/writes

• Web:  real-time inserts, updates, and queries. Auto-sharding
 (scalability) and replication are provided.

• Real-time   stats/analytics

                                16
LESS GOOD FOR


• Systems   with heavy transactional nature

• Traditional   Business Intelligence

• (obviously)   System and problems requiring SQL



                                   17
SHARDING /1

• Horizontal   scalability: MongoDB auto-sharding

   • partitioning   by keys

   • auto-balancing

   • easy   addition of new servers

   • no   single points-of-failure

   • automatic    failover/replica-sets
                                     18
SHARDING /2
                mongod        mongod            mongod

                mongod        mongod      ...   mongod   Shards


                mongod        mongod            mongod



Config servers



mongod
                         mongos        mongos   ...


mongod

mongod                   Client

                                  19
DRIVERS

• C#   and .NET              • Python, Ruby, Delphi

• C, C++                     • Scala

• Erlang, Perl               • Clojure

• Haskell                    • Go, Objective   C

• Java, Javascript           • Smalltalk

• PHP                        • ...
                        20
PyMongo

• Recommended       MongoDB driver for the Python language

• An   easy way to install it (Mac, Linux):



       •   easy_install pymongo

       •   easy_install -U pymongo


                                   21
QUICK-START: INSERT
• (obviously)   mongod must be running ;-)
import pymongo
from pymongo import Connection

conn = Connection()     # default localhost:27017; conn=Connection('myhost',9999)

db = conn['test_db']     # gets the database

test_coll = db['testcoll']     # gets the desired collection

doc = {"name":"slides.txt", "author":"Antonio", "type":"text", "tags":
["mongodb", "python", "slides"]}   # a dict

test_coll.insert(doc)     # inserts document into the collection



• lazycreation: collections and databases are created when the
 first document is inserted into them
                                          22
QUICK-START: QUERY
res = test_coll.find_one()        # gets one document


query = {"author":"Antonio"}      # a query document

res = test_coll.find_one(query)      # searches for one document



for doc in test_coll.find(query):        # using Cursors on multiple docs
    print doc
    ...


test_coll.count()     # counts the docs in the collection




                                          23
NOT COVERED (HERE)

• GridFS:  binary data storage is limited to 16MB in DB, so
 GridFS transparently splits large files among multiple
 documents

• MapReduce: batch      processing of data and aggregation
 operations

• GeoSpatial   Indexing: two-dimensional indexing for
 location-based queries (e.g., retrieve the n closest restaurants
 to my location)
                                24
IN PRODUCTION (some...)




           25
26
Paraimpu LOVES MongoDB

• MongoDB      powers Paraimpu, our Social Web of Things tool

• great   data heterogeneity

• real-time   thousands, small data inserts/queries

• performances

• horizontal   scalability

• easy   of use, development is funny!
                                  27
REFERENCES
• http://www.mongodb.org/

• http://www.mongodb.org/display/DOCS/Manual

• http://www.mongodb.org/display/DOCS/Slides+and+Video




• pymongo:    http://api.mongodb.org/python/



• Paraimpu:   http://paraimpu.crs4.it
                                  28
THANK YOU

Antonio Pintus

                 email:     pintux@crs4.it

                 twitter:   @apintux

                                       29

Más contenido relacionado

La actualidad más candente

PDF.JS at SwissJeese 2012
PDF.JS at SwissJeese 2012PDF.JS at SwissJeese 2012
PDF.JS at SwissJeese 2012Julian Viereck
 
Timyang新浪微博设计谈
Timyang新浪微博设计谈Timyang新浪微博设计谈
Timyang新浪微博设计谈Cevin Cheung
 
Back to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationBack to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationMongoDB
 
Beyond the Basics 2: Aggregation Framework
Beyond the Basics 2: Aggregation Framework Beyond the Basics 2: Aggregation Framework
Beyond the Basics 2: Aggregation Framework MongoDB
 
Back to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation FrameworkBack to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation FrameworkMongoDB
 
Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)Itamar Haber
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and PythonMike Bright
 
微博cache设计谈
微博cache设计谈微博cache设计谈
微博cache设计谈Tim Y
 
Debugging and Testing ES Systems
Debugging and Testing ES SystemsDebugging and Testing ES Systems
Debugging and Testing ES SystemsChris Birchall
 
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...Miguel Gallardo
 
Advanced Redis data structures
Advanced Redis data structuresAdvanced Redis data structures
Advanced Redis data structuresamix3k
 
Cutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQueryCutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQueryWilliam Candillon
 
Fazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchFazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchPedro Franceschi
 
MongoDB, Hadoop and humongous data - MongoSV 2012
MongoDB, Hadoop and humongous data - MongoSV 2012MongoDB, Hadoop and humongous data - MongoSV 2012
MongoDB, Hadoop and humongous data - MongoSV 2012Steven Francia
 
Benchx: An XQuery benchmarking web application
Benchx: An XQuery benchmarking web application Benchx: An XQuery benchmarking web application
Benchx: An XQuery benchmarking web application Andy Bunce
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012sullis
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data ModelingDATAVERSITY
 

La actualidad más candente (20)

PDF.JS at SwissJeese 2012
PDF.JS at SwissJeese 2012PDF.JS at SwissJeese 2012
PDF.JS at SwissJeese 2012
 
Timyang新浪微博设计谈
Timyang新浪微博设计谈Timyang新浪微博设计谈
Timyang新浪微博设计谈
 
Back to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationBack to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB Application
 
Beyond the Basics 2: Aggregation Framework
Beyond the Basics 2: Aggregation Framework Beyond the Basics 2: Aggregation Framework
Beyond the Basics 2: Aggregation Framework
 
Back to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation FrameworkBack to Basics Webinar 5: Introduction to the Aggregation Framework
Back to Basics Webinar 5: Introduction to the Aggregation Framework
 
KeyValue Stores
KeyValue StoresKeyValue Stores
KeyValue Stores
 
Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)Redis Use Patterns (DevconTLV June 2014)
Redis Use Patterns (DevconTLV June 2014)
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and Python
 
微博cache设计谈
微博cache设计谈微博cache设计谈
微博cache设计谈
 
Debugging and Testing ES Systems
Debugging and Testing ES SystemsDebugging and Testing ES Systems
Debugging and Testing ES Systems
 
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
Code decoupling from Symfony (and others frameworks) - PHP Conference Brasil ...
 
Advanced Redis data structures
Advanced Redis data structuresAdvanced Redis data structures
Advanced Redis data structures
 
Cutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQueryCutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQuery
 
ElasticSearch
ElasticSearchElasticSearch
ElasticSearch
 
Fazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchFazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearch
 
Mongodb
MongodbMongodb
Mongodb
 
MongoDB, Hadoop and humongous data - MongoSV 2012
MongoDB, Hadoop and humongous data - MongoSV 2012MongoDB, Hadoop and humongous data - MongoSV 2012
MongoDB, Hadoop and humongous data - MongoSV 2012
 
Benchx: An XQuery benchmarking web application
Benchx: An XQuery benchmarking web application Benchx: An XQuery benchmarking web application
Benchx: An XQuery benchmarking web application
 
Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012Getting started with MongoDB and Scala - Open Source Bridge 2012
Getting started with MongoDB and Scala - Open Source Bridge 2012
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
 

Similar a MongoDB: a gentle, friendly overview

10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCupWebGeek Philippines
 
Mongodb intro
Mongodb introMongodb intro
Mongodb introchristkv
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongoMichael Bright
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBSean Laurent
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBMongoDB
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDBNorberto Leite
 
Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)Chris Richardson
 
MongoDB NYC Python
MongoDB NYC PythonMongoDB NYC Python
MongoDB NYC PythonMike Dirolf
 
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyOSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyNETWAYS
 
MongoDB at ZPUGDC
MongoDB at ZPUGDCMongoDB at ZPUGDC
MongoDB at ZPUGDCMike Dirolf
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlTO THE NEW | Technology
 
MongoDB EuroPython 2009
MongoDB EuroPython 2009MongoDB EuroPython 2009
MongoDB EuroPython 2009Mike Dirolf
 
Data as Documents: Overview and intro to MongoDB
Data as Documents: Overview and intro to MongoDBData as Documents: Overview and intro to MongoDB
Data as Documents: Overview and intro to MongoDBMitch Pirtle
 
Webinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDBWebinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDBMongoDB
 

Similar a MongoDB: a gentle, friendly overview (20)

10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo
 
Mongo DB
Mongo DB Mongo DB
Mongo DB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)
 
MongoDB NYC Python
MongoDB NYC PythonMongoDB NYC Python
MongoDB NYC Python
 
No sql Database
No sql DatabaseNo sql Database
No sql Database
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB at GUL
MongoDB at GULMongoDB at GUL
MongoDB at GUL
 
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyOSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
 
MongoDB at ZPUGDC
MongoDB at ZPUGDCMongoDB at ZPUGDC
MongoDB at ZPUGDC
 
MongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behlMongoDB using Grails plugin by puneet behl
MongoDB using Grails plugin by puneet behl
 
MongoDB EuroPython 2009
MongoDB EuroPython 2009MongoDB EuroPython 2009
MongoDB EuroPython 2009
 
Data as Documents: Overview and intro to MongoDB
Data as Documents: Overview and intro to MongoDBData as Documents: Overview and intro to MongoDB
Data as Documents: Overview and intro to MongoDB
 
Wmware NoSQL
Wmware NoSQLWmware NoSQL
Wmware NoSQL
 
Webinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDBWebinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDB
 
Mondodb
MondodbMondodb
Mondodb
 

Más de Antonio Pintus

Internet of Things, a che punto siamo?
Internet of Things, a che punto siamo?Internet of Things, a che punto siamo?
Internet of Things, a che punto siamo?Antonio Pintus
 
Humanizing the Internet of Things
Humanizing the Internet of ThingsHumanizing the Internet of Things
Humanizing the Internet of ThingsAntonio Pintus
 
Introduzione all'Internet of Things
Introduzione all'Internet of ThingsIntroduzione all'Internet of Things
Introduzione all'Internet of ThingsAntonio Pintus
 
Paraimpu @ Tiscali Open Campus
Paraimpu @ Tiscali Open CampusParaimpu @ Tiscali Open Campus
Paraimpu @ Tiscali Open CampusAntonio Pintus
 
Internet of Things & Paraimpu
Internet of Things & ParaimpuInternet of Things & Paraimpu
Internet of Things & ParaimpuAntonio Pintus
 
Paraimpu @ World Wide Rome
Paraimpu @ World Wide RomeParaimpu @ World Wide Rome
Paraimpu @ World Wide RomeAntonio Pintus
 
Paraimpu PechaKucha Night Cagliari #02
Paraimpu PechaKucha Night Cagliari #02Paraimpu PechaKucha Night Cagliari #02
Paraimpu PechaKucha Night Cagliari #02Antonio Pintus
 
Paraimpu: a social tool for the Web of Things @ WoT2011
Paraimpu: a social tool for the Web of Things @ WoT2011Paraimpu: a social tool for the Web of Things @ WoT2011
Paraimpu: a social tool for the Web of Things @ WoT2011Antonio Pintus
 
Paraimpu: a social tool for the Web of Things
Paraimpu: a social tool for the Web of ThingsParaimpu: a social tool for the Web of Things
Paraimpu: a social tool for the Web of ThingsAntonio Pintus
 
Paraimpu: un social tool per il Web of Things
Paraimpu: un social tool per il Web of ThingsParaimpu: un social tool per il Web of Things
Paraimpu: un social tool per il Web of ThingsAntonio Pintus
 
Un mare di oggetti in comunicazione tra loro (c'era una volta il Web)
Un mare di oggetti in comunicazione tra loro (c'era una volta il Web)Un mare di oggetti in comunicazione tra loro (c'era una volta il Web)
Un mare di oggetti in comunicazione tra loro (c'era una volta il Web)Antonio Pintus
 
Connecting Smart Things through Web services Orchestrations
Connecting Smart Things through Web services OrchestrationsConnecting Smart Things through Web services Orchestrations
Connecting Smart Things through Web services OrchestrationsAntonio Pintus
 
Building a complete SOA application with NetBeans 5.5
Building a complete SOA application with NetBeans 5.5Building a complete SOA application with NetBeans 5.5
Building a complete SOA application with NetBeans 5.5Antonio Pintus
 

Más de Antonio Pintus (15)

Internet of Things, a che punto siamo?
Internet of Things, a che punto siamo?Internet of Things, a che punto siamo?
Internet of Things, a che punto siamo?
 
Humanizing the Internet of Things
Humanizing the Internet of ThingsHumanizing the Internet of Things
Humanizing the Internet of Things
 
Introduzione all'Internet of Things
Introduzione all'Internet of ThingsIntroduzione all'Internet of Things
Introduzione all'Internet of Things
 
Paraimpu @ Tiscali Open Campus
Paraimpu @ Tiscali Open CampusParaimpu @ Tiscali Open Campus
Paraimpu @ Tiscali Open Campus
 
Internet of Things & Paraimpu
Internet of Things & ParaimpuInternet of Things & Paraimpu
Internet of Things & Paraimpu
 
Paraimpu @ WWW 2012
Paraimpu @ WWW 2012Paraimpu @ WWW 2012
Paraimpu @ WWW 2012
 
Paraimpu @ World Wide Rome
Paraimpu @ World Wide RomeParaimpu @ World Wide Rome
Paraimpu @ World Wide Rome
 
Paraimpu PechaKucha Night Cagliari #02
Paraimpu PechaKucha Night Cagliari #02Paraimpu PechaKucha Night Cagliari #02
Paraimpu PechaKucha Night Cagliari #02
 
Paraimpu: a social tool for the Web of Things @ WoT2011
Paraimpu: a social tool for the Web of Things @ WoT2011Paraimpu: a social tool for the Web of Things @ WoT2011
Paraimpu: a social tool for the Web of Things @ WoT2011
 
Paraimpu: a social tool for the Web of Things
Paraimpu: a social tool for the Web of ThingsParaimpu: a social tool for the Web of Things
Paraimpu: a social tool for the Web of Things
 
Paraimpu: un social tool per il Web of Things
Paraimpu: un social tool per il Web of ThingsParaimpu: un social tool per il Web of Things
Paraimpu: un social tool per il Web of Things
 
Un mare di oggetti in comunicazione tra loro (c'era una volta il Web)
Un mare di oggetti in comunicazione tra loro (c'era una volta il Web)Un mare di oggetti in comunicazione tra loro (c'era una volta il Web)
Un mare di oggetti in comunicazione tra loro (c'era una volta il Web)
 
Connecting Smart Things through Web services Orchestrations
Connecting Smart Things through Web services OrchestrationsConnecting Smart Things through Web services Orchestrations
Connecting Smart Things through Web services Orchestrations
 
Parliamo di SOA
Parliamo di SOAParliamo di SOA
Parliamo di SOA
 
Building a complete SOA application with NetBeans 5.5
Building a complete SOA application with NetBeans 5.5Building a complete SOA application with NetBeans 5.5
Building a complete SOA application with NetBeans 5.5
 

Último

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Último (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

MongoDB: a gentle, friendly overview

  • 1. A gentle, friendly overview Antonio Pintus CRS4, 08/09/2011 1
  • 2. NOSQL /1 • MongoDB belongs to the NoSQL databases family: • non-relational • document-oriented • no prefixed, rigid, database schemas • no joins • horizontal scalability 2
  • 3. NOSQL /2 • NoSQL DB family includes several DB types: • document/oriented: mongoDB, CouchDB, ... • Key Value / Tuple Store: Redis, ... • Graph databases: Neo4j, ... • ... 3
  • 4. MongoDB • Performant: C++ • document-based queries • Schema-free • Map/Reduce • Full index support • GridFS • No transactions •a JavaScript interactive shell • Scalable: replication + sharding 4
  • 5. SCHEMA-FREE • Schema-free collections = NO TABLES! •A Mongo deployment (server) holds a set of databases •A database holds a set of collections •A collection holds a set of documents •A document is a set of fields: key-value pair (BSON) •A key is a name (string), a value is a basic type like string, integer, float, timestamp, binary, etc.,a document, or an array of values 5
  • 6. DATA FORMAT • document/oriented • stores JSON-style documents: BSON (Binary JSON): • JSON + other data types. E.g., Date type and a BinData type. • Can reference other documents • lightweight, traversable, efficient 6
  • 7. BSON {! "_id" : ObjectId("4dcec9a0af391a0d53000003"), ! "servicetype" : "sensor", ! "description" : "it’s only rock’n’roll but I like it", ! "policy" : "PUBLIC", ! "owner" : "User001", ! "date_created" : "2011-05-02 17:11:28.874086", ! "shortname" : "SampleSensor", ! "content-type" : "text/plain", ! "icon" : "http://myserver.com/images/sens.png" } 7
  • 8. COLLECTIONS • More or less, same concept as “table” but dynamic, schema- free • collection of BSON documents • documents can have heterogeneous data structure in the same collection 8
  • 9. QUERIES • query by documents • Examples (using the interactive shell): • db.mycollection.find( {"policy" : "PUBLIC"} ); • db.mycollection.findOne({"policy" : "PUBLIC", “owner”:”User001”}); • db.mycollection.find({"policy" : "PUBLIC", “owner”:”User001”}).limit(2); • db.mycollection.find( {"policy" : "PUBLIC"}, {“shortname”:1} ); • db.mycollection.find({"counter": {$gt:2}}); • conditional ops: <, <=, >, >=, $and, $in, $or, $nor, ... 9
  • 10. INDEXES • Full index support: index on any attribute (including multiple) • increase query performance • indexes are implemented as “B-Tree” indexes • data overhead for inserts and deletes, don’t abuse! • db.mycollection.ensureIndex( {"servicetype" : 1} ); • db.mycollection.ensureIndex( {"servicetype" : 1, “owner”:-1} ); • db.mycollection.getIndexes() • db.system.indexes.find() 10
  • 11. INSERTS • Simplicity • db.mycollection.insert({“a”:”abc”,...}) • var doc = {“name”:”mongodb”,...}; • db.mycollection.insert(doc); 11
  • 12. UPDATES 1. replace entire document 2. atomic, in-place updates • db.collection.update( criteria, objNew, upsert, multi ) • criteria: the query • objNew: updated object or $ operators (e.g., $inc, $set) which manipulate the object • upsert: if the record(s) do not exist, insert one. • multi: if all documents matching criteria should be updated • db.collection.save(...): single object update with upsert 12
  • 13. UPDATES /2 • atomic, in-place updates = highly efficient • provides special operators • db.mycollection.update( { “shortname”:"Arduino" }, { $inc: { n : 1 } } ); • db.mycollection.update( { “shortname”:"Arduino" }, { $set: { “shortname” : “OldArduino” } } ); • other atomic ops: $unset, $push, $pushAll, $addToSet, $pop, $pull, $rename, ... 13
  • 14. Mongo DISTRIBUTION • Mac, Linux, Solaris, Win • mongod: database server. • By default, port=27017, store path=/data/db. • Override with --dbpath, --port command options • mongo: interactive JavaScript shell • mongos: sharding controller server 14
  • 15. MISCELLANEOUS: REST • mongod provides a basic REST interface • launch it with --rest option: default port=28017 • http://localhost:28017/mydb/mycollection/ • http://localhost:28017/mydb/mycollection/?filter_shortname=Arduino • http://localhost:28017/mydb/mycollection/?filter_shortname=Arduino • http://localhost:28017/mydb/mycollection/? filter_shortname=Arduino&limit=10 15
  • 16. GOOD FOR • event logging • high performance small read/writes • Web: real-time inserts, updates, and queries. Auto-sharding (scalability) and replication are provided. • Real-time stats/analytics 16
  • 17. LESS GOOD FOR • Systems with heavy transactional nature • Traditional Business Intelligence • (obviously) System and problems requiring SQL 17
  • 18. SHARDING /1 • Horizontal scalability: MongoDB auto-sharding • partitioning by keys • auto-balancing • easy addition of new servers • no single points-of-failure • automatic failover/replica-sets 18
  • 19. SHARDING /2 mongod mongod mongod mongod mongod ... mongod Shards mongod mongod mongod Config servers mongod mongos mongos ... mongod mongod Client 19
  • 20. DRIVERS • C# and .NET • Python, Ruby, Delphi • C, C++ • Scala • Erlang, Perl • Clojure • Haskell • Go, Objective C • Java, Javascript • Smalltalk • PHP • ... 20
  • 21. PyMongo • Recommended MongoDB driver for the Python language • An easy way to install it (Mac, Linux): • easy_install pymongo • easy_install -U pymongo 21
  • 22. QUICK-START: INSERT • (obviously) mongod must be running ;-) import pymongo from pymongo import Connection conn = Connection() # default localhost:27017; conn=Connection('myhost',9999) db = conn['test_db'] # gets the database test_coll = db['testcoll'] # gets the desired collection doc = {"name":"slides.txt", "author":"Antonio", "type":"text", "tags": ["mongodb", "python", "slides"]} # a dict test_coll.insert(doc) # inserts document into the collection • lazycreation: collections and databases are created when the first document is inserted into them 22
  • 23. QUICK-START: QUERY res = test_coll.find_one() # gets one document query = {"author":"Antonio"} # a query document res = test_coll.find_one(query) # searches for one document for doc in test_coll.find(query): # using Cursors on multiple docs print doc ... test_coll.count() # counts the docs in the collection 23
  • 24. NOT COVERED (HERE) • GridFS: binary data storage is limited to 16MB in DB, so GridFS transparently splits large files among multiple documents • MapReduce: batch processing of data and aggregation operations • GeoSpatial Indexing: two-dimensional indexing for location-based queries (e.g., retrieve the n closest restaurants to my location) 24
  • 26. 26
  • 27. Paraimpu LOVES MongoDB • MongoDB powers Paraimpu, our Social Web of Things tool • great data heterogeneity • real-time thousands, small data inserts/queries • performances • horizontal scalability • easy of use, development is funny! 27
  • 28. REFERENCES • http://www.mongodb.org/ • http://www.mongodb.org/display/DOCS/Manual • http://www.mongodb.org/display/DOCS/Slides+and+Video • pymongo: http://api.mongodb.org/python/ • Paraimpu: http://paraimpu.crs4.it 28
  • 29. THANK YOU Antonio Pintus email: pintux@crs4.it twitter: @apintux 29