SlideShare una empresa de Scribd logo
1 de 22
Code MassimoB gets you a 25% discount off the list price
Back to Basics 2016 : Webinar 3
Pensare a Documenti
Massimo Brignoli
Principal Solution Architect, EMEA
massimo@mongodb.com
@massimobrignoli
4
Review
• Webinar 1 : Introduzione a NoSQL
– Tipi di Database NoSQL
– MongoDB è un database a documenti
– Replica Set e Shard
• Webinar 2
– Costruire una semplice applicazione
– Aggiungere gli indici
– Usare Explain per misurare le operazioni
5
Pensare a Documenti
• I Documenti in MongoDB sono Javascript Objects (JSON)
• Sono codificati come BSON
– BSON è “Binary JSON”
– BSON permette un encoding e decoding efficiente dei
JSON
• Richiesto per una trasmissione dati e gestione dello spazio
disco efficiente.
• Elimina la necessità di fare il aprsing del testo di tutti I sotto
oggetti
• Le specifiche si trovano su http://bsonspec.org/
6
Esempio di Documento
{
first_name: ‘Paul’,
surname: ‘Miller’,
cell: 447557505611,
city: ‘London’,
location: [45.123,47.232],
Profession: [‘banking’, ‘finance’, ‘trader’],
cars: [
{ model: ‘Bentley’,
year: 1973,
value: 100000, … },
{ model: ‘Rolls Royce’,
year: 1965,
value: 330000, … }
]
}
Fields can contain an array
of sub-documents
Fields
Typed field values
Fields can
contain arrays
7
Data Store – Key Value
Key 1 Value
Key 1 Value
Key 1 Value
8
Data Store - Relazionale
Key 1
Value 1
Value 1
Value 1
Value 1
Key 2
Value 1
Value 1
Value 1
Value 1
Key 3
Value 1
Value 1
Value 1
Value 1
Key 4
Value 1
Value 1
Value 1
Value 1
9
Data Store - Documenti
Key3
Key4
Key5
Value 3
Value 5
Value 4Key6
Value 5Key7
Value 2
Value 1Key1
Key1
Key1
Key2
10
La Forma dei Sottodocumenti
{ “key1” : “value 1” }
{ “key1” : { “key2” : “value 1”,
“key3” : { “key4” : “value 3”,
“key5” : “value 4” }
}
{ “key1” : { “key6” : “value 5”,
“key7” : “value 6” }
}
11
Alcuni esempi di Query
# Will find the first two documents
db.demo.find( { “key1” : “value” } )
# find the second document by nested value
db.demo.find( { "key1.key3.key4" : "value 3" } )
# will find the third document
db.demo.find( { "key1.key6" : "value 4" } )
12
Modellazione e Cardinalità
• One to One
–Titolo al blog post
• One to Many
–Blog post ai commenti
• One to Millions
–Blog post sulle visite al sito (e.g. Huffington Post)
13
One To One
{
“Title” : “This is a blog post”,
“Body” : “This is the body text of a very
short blog post”,
…
}
Possiamo indicizzare sia “Title” che “Body”.
14
One to Many
{
“Title” : “This is a blog post”,
“Body” : “This is the body text”,
“Comments” : [ { “name” : “Joe Drumgoole”,
“email” : “Joe.Drumgoole@mongodb.com”,
“comment” : “I love your writing style” },
{ “name” : “John Smith”,
“email” : “John.Smith@example.com”,
“comment” : “I hate your writing style” }]
}
Se ci aspettiamo un basso numero di commenti possiamo
incapsularli all’interno del documento principale
15
Criticità Principali
• Come scrivete sul DB?
–I commenti sono inseriti più frequentemente dei post.
–I Commenti possono avere immagini, tags, grandi pezzi
di testo
• Come leggete dal DB?
–I commenti possono non essere visualizzati
–Possono essere mostrati in una pagina dedicata
–Gli utenti raramenti leggono tutti i commenti
16
Approccio Alternativo: Collection Separata
• Mantenere tutti I commenti in una colleciton separata
• Aggiungere le referenze ai commenti come un array di ID dei commenti
• Richiede due query per visualizzare il blog post e i relativi commenti
• Richiede due scritture per create un commento
{
_id : ObjectID( “AAAA” ),
name : “Massimo Brignoli”,
email : “massimo@mongodb.com”,
comment :“I love your writing style”,
}
{
_id : ObjectID( “AAAB” ),
name : “John Smith”,
email : “Joe.Drumgoole@mongodb.com”,
comment :“I hate your writing style”,
}
{
“_id” : ObjectID( “ZZZZ” ),
“Title” : “A Blog Title”,
“Body” : “A blog post”,
“comments” : [ ObjectID( “AAAA” ),
ObjectID( “AAAB” )]
}
{
“_id” : ObjectID( “ZZZZ” ),
“Title” : “A Blog Title”,
“Body” : “A blog post”,
“comments” : []
}
17
Approccio Migliore – Un Ibrido
{
“_id” : ObjectID( “ZZZZ” ),
“Title” : “A Blog Title”,
“Body” : “A blog post”,
“comments” : [{
“_id” : ObjectID( “AAAA” )
“name” : “Joe Drumgoole”,
“email” : “Joe.D@mongodb.com”,
comment :“I love your writing style”,
}
{
_id : ObjectID( “AAAB” ),
name : “John Smith”,
email : “Joe.Drumgoole@mongodb.com”,
comment :“I hate your writing style”,
}]
}
{
“_post_jd” : ObjectID( “ZZZZ” ),
“comments” : [{
“_id” : ObjectID( “AAAA” )
“name” : “Joe Drumgoole”,
“email” : “Joe.D@mongodb.com”,
“comment” :“I love your writing
style”,
}
{...},{...},{...},{...},{...},{...}
,{..},{...},{...},{...} ]
18
E la Relazione One to Millions?
• Cosa succederebbe se tracciassimo la posizione del mouse per “heat
tracking”?
– Ogni utente genererebbe centinaia di data point per visita.
– Migliaia di data points per post
– Milioni di data point per sito
• Invertiamo ill modello:
– Memorizziamo un blog ID per evento
{
“post_id” : ObjectID(“ZZZZ”),
“timestamp” : ISODate("2005-01-02T00:00:00Z”),
“location” : [24, 34]
“click” : False,
}
19
Ma – C’e’un numero finito di eventi al secondo
{
post_id : ObjectID ( “ZZZZ” ),
timeStamp: ISODate("2005-01-02T00:00:00Z”),
events : {
0 : { 0 : { <Info> }, 1 : { <Info> }, … 99: { <Info> }},
1 : { 0 : { <Info> }, 1 : { <Info> }, … 99: { <Info> }},
2 : { 0 : { <Info> }, 1 : { <Info> }, … 99: { <Info> }},
3 : { 0 : { <Info> }, 1 : { <Info> }, … 99: { <Info> }},
...
59 :{ 0 : { <Info> }, 1 : { <Info> }, … 99: { <Info> }}
}
20
Linee Guida
• Icapsulare SEMPRE gli oggetti con relazioni one to one
• Controllate gli accessi in lettura e scrittura per determinare quando spostare I
dati all’esterno
• Non rimanete bloccati nel pensiero di “un record” per tutto
• Abbracciate la gerarchia
• Pensate alla cardinalità
• Gestire la crescita aggiungendo documenti non aumentando la dimensione
dei documenti
• Pensate bene agli indici
21
Prossimo Webinar : Indicizzazione Avanzata, Indici Testuali e
Geografici
• Il support Full text permette ad un utente di indicizzare tutto il
contenuto testuale del suo database abilitando ricerche del tipo
google sulla loro base dati
• Gli indici geografici permettono ad un utente di memorizzare
coordinate geografiche e di effettuare ricerche basate sulla
prossimità tra due punti
05 Luglio 2016, 11:00 GMT.
Back to Basics, webinar 3: Riflessioni sulla progettazione degli schemi nei documenti

Más contenido relacionado

La actualidad más candente

20140311 app dev series - 01 - introduction - italian
20140311   app dev series - 01 - introduction - italian20140311   app dev series - 01 - introduction - italian
20140311 app dev series - 01 - introduction - italianMongoDB
 
Back to Basics, webinar 6: Messa in esercizio
Back to Basics, webinar 6: Messa in esercizioBack to Basics, webinar 6: Messa in esercizio
Back to Basics, webinar 6: Messa in esercizioMongoDB
 
Schema design - Corso base di MongoDB
Schema design - Corso base di MongoDBSchema design - Corso base di MongoDB
Schema design - Corso base di MongoDBAlberto Olla
 
Deploy MongoDB su Infrastruttura Amazon Web Services
Deploy MongoDB su Infrastruttura Amazon Web ServicesDeploy MongoDB su Infrastruttura Amazon Web Services
Deploy MongoDB su Infrastruttura Amazon Web ServicesStefano Dindo
 
Back to Basics webinar 1 IT 17 - Introduzione ai NoSQL
Back to Basics webinar 1 IT 17 - Introduzione ai NoSQLBack to Basics webinar 1 IT 17 - Introduzione ai NoSQL
Back to Basics webinar 1 IT 17 - Introduzione ai NoSQLMongoDB
 
Advanced Database Models and Architectures: Big Data: MySQL VS MongoDB
Advanced Database Models and Architectures: Big Data: MySQL VS MongoDBAdvanced Database Models and Architectures: Big Data: MySQL VS MongoDB
Advanced Database Models and Architectures: Big Data: MySQL VS MongoDBLuca Marignati
 
MongoDb and Scala SpringFramework Meeting
MongoDb and Scala SpringFramework MeetingMongoDb and Scala SpringFramework Meeting
MongoDb and Scala SpringFramework Meetingguest67beeb9
 
MongoDB SpringFramework Meeting september 2009
MongoDB SpringFramework Meeting september 2009MongoDB SpringFramework Meeting september 2009
MongoDB SpringFramework Meeting september 2009Massimiliano Dessì
 
MongoDB Scala Roma SpringFramework Meeting2009
MongoDB Scala Roma SpringFramework Meeting2009MongoDB Scala Roma SpringFramework Meeting2009
MongoDB Scala Roma SpringFramework Meeting2009Massimiliano Dessì
 
How to develop modern web application - With no money and no Javascript
How to develop modern web application - With no money and no JavascriptHow to develop modern web application - With no money and no Javascript
How to develop modern web application - With no money and no JavascriptAndrea Tosato
 
Back to Basics 4: Introduzione al partizionamento orizzontale (sharding)
Back to Basics 4: Introduzione al partizionamento orizzontale (sharding)Back to Basics 4: Introduzione al partizionamento orizzontale (sharding)
Back to Basics 4: Introduzione al partizionamento orizzontale (sharding)MongoDB
 
Ricerche performanti con ElasticSearch
Ricerche performanti con ElasticSearchRicerche performanti con ElasticSearch
Ricerche performanti con ElasticSearchseeweb
 
MongoDB User Group Padova - Overviews iniziale su MongoDB
MongoDB User Group Padova - Overviews iniziale su MongoDBMongoDB User Group Padova - Overviews iniziale su MongoDB
MongoDB User Group Padova - Overviews iniziale su MongoDBStefano Dindo
 
Scala Programming Linux Day 2009
Scala Programming Linux Day 2009Scala Programming Linux Day 2009
Scala Programming Linux Day 2009Massimiliano Dessì
 
Ricerche performanti con ElasticSearch sfruttando la potenza e la flessibilit...
Ricerche performanti con ElasticSearch sfruttando la potenza e la flessibilit...Ricerche performanti con ElasticSearch sfruttando la potenza e la flessibilit...
Ricerche performanti con ElasticSearch sfruttando la potenza e la flessibilit...Kelyon Srl
 
Couchbase Meetup - "Introduzione a NoSQL e Couchbase"
Couchbase Meetup - "Introduzione a NoSQL e Couchbase"Couchbase Meetup - "Introduzione a NoSQL e Couchbase"
Couchbase Meetup - "Introduzione a NoSQL e Couchbase"Franco Caporale
 
Abusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side StorageAbusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side Storageameft
 

La actualidad más candente (17)

20140311 app dev series - 01 - introduction - italian
20140311   app dev series - 01 - introduction - italian20140311   app dev series - 01 - introduction - italian
20140311 app dev series - 01 - introduction - italian
 
Back to Basics, webinar 6: Messa in esercizio
Back to Basics, webinar 6: Messa in esercizioBack to Basics, webinar 6: Messa in esercizio
Back to Basics, webinar 6: Messa in esercizio
 
Schema design - Corso base di MongoDB
Schema design - Corso base di MongoDBSchema design - Corso base di MongoDB
Schema design - Corso base di MongoDB
 
Deploy MongoDB su Infrastruttura Amazon Web Services
Deploy MongoDB su Infrastruttura Amazon Web ServicesDeploy MongoDB su Infrastruttura Amazon Web Services
Deploy MongoDB su Infrastruttura Amazon Web Services
 
Back to Basics webinar 1 IT 17 - Introduzione ai NoSQL
Back to Basics webinar 1 IT 17 - Introduzione ai NoSQLBack to Basics webinar 1 IT 17 - Introduzione ai NoSQL
Back to Basics webinar 1 IT 17 - Introduzione ai NoSQL
 
Advanced Database Models and Architectures: Big Data: MySQL VS MongoDB
Advanced Database Models and Architectures: Big Data: MySQL VS MongoDBAdvanced Database Models and Architectures: Big Data: MySQL VS MongoDB
Advanced Database Models and Architectures: Big Data: MySQL VS MongoDB
 
MongoDb and Scala SpringFramework Meeting
MongoDb and Scala SpringFramework MeetingMongoDb and Scala SpringFramework Meeting
MongoDb and Scala SpringFramework Meeting
 
MongoDB SpringFramework Meeting september 2009
MongoDB SpringFramework Meeting september 2009MongoDB SpringFramework Meeting september 2009
MongoDB SpringFramework Meeting september 2009
 
MongoDB Scala Roma SpringFramework Meeting2009
MongoDB Scala Roma SpringFramework Meeting2009MongoDB Scala Roma SpringFramework Meeting2009
MongoDB Scala Roma SpringFramework Meeting2009
 
How to develop modern web application - With no money and no Javascript
How to develop modern web application - With no money and no JavascriptHow to develop modern web application - With no money and no Javascript
How to develop modern web application - With no money and no Javascript
 
Back to Basics 4: Introduzione al partizionamento orizzontale (sharding)
Back to Basics 4: Introduzione al partizionamento orizzontale (sharding)Back to Basics 4: Introduzione al partizionamento orizzontale (sharding)
Back to Basics 4: Introduzione al partizionamento orizzontale (sharding)
 
Ricerche performanti con ElasticSearch
Ricerche performanti con ElasticSearchRicerche performanti con ElasticSearch
Ricerche performanti con ElasticSearch
 
MongoDB User Group Padova - Overviews iniziale su MongoDB
MongoDB User Group Padova - Overviews iniziale su MongoDBMongoDB User Group Padova - Overviews iniziale su MongoDB
MongoDB User Group Padova - Overviews iniziale su MongoDB
 
Scala Programming Linux Day 2009
Scala Programming Linux Day 2009Scala Programming Linux Day 2009
Scala Programming Linux Day 2009
 
Ricerche performanti con ElasticSearch sfruttando la potenza e la flessibilit...
Ricerche performanti con ElasticSearch sfruttando la potenza e la flessibilit...Ricerche performanti con ElasticSearch sfruttando la potenza e la flessibilit...
Ricerche performanti con ElasticSearch sfruttando la potenza e la flessibilit...
 
Couchbase Meetup - "Introduzione a NoSQL e Couchbase"
Couchbase Meetup - "Introduzione a NoSQL e Couchbase"Couchbase Meetup - "Introduzione a NoSQL e Couchbase"
Couchbase Meetup - "Introduzione a NoSQL e Couchbase"
 
Abusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side StorageAbusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side Storage
 

Similar a Back to Basics, webinar 3: Riflessioni sulla progettazione degli schemi nei documenti

I Graph Database: analisi del comportamento degli utenti
I Graph Database: analisi del comportamento degli utentiI Graph Database: analisi del comportamento degli utenti
I Graph Database: analisi del comportamento degli utentiThinkOpen
 
MongoDB - Back to Basics 2017 - Introduzione a NoSQL
MongoDB - Back to Basics 2017 - Introduzione a NoSQLMongoDB - Back to Basics 2017 - Introduzione a NoSQL
MongoDB - Back to Basics 2017 - Introduzione a NoSQLMassimo Brignoli
 
Entity Framework 6 for developers, Code-First!
Entity Framework 6 for developers, Code-First!Entity Framework 6 for developers, Code-First!
Entity Framework 6 for developers, Code-First!Michael Denny
 
Love Your Database (ESC 2k16)
Love Your Database (ESC 2k16)Love Your Database (ESC 2k16)
Love Your Database (ESC 2k16)PgTraining
 
JSON-LD e Schema.org per il Web Semantico: SMX milano 2015
JSON-LD e Schema.org per il Web Semantico: SMX milano 2015JSON-LD e Schema.org per il Web Semantico: SMX milano 2015
JSON-LD e Schema.org per il Web Semantico: SMX milano 2015Sante J. Achille
 
What's Big Data? - Big Data Tech - 2015 - Firenze
What's Big Data? - Big Data Tech - 2015 - FirenzeWhat's Big Data? - Big Data Tech - 2015 - Firenze
What's Big Data? - Big Data Tech - 2015 - FirenzeAlberto Paro
 
Introduzione ai Big Data e alla scienza dei dati - Exploratory Data Analysis
Introduzione ai Big Data e alla scienza dei dati - Exploratory Data AnalysisIntroduzione ai Big Data e alla scienza dei dati - Exploratory Data Analysis
Introduzione ai Big Data e alla scienza dei dati - Exploratory Data AnalysisVincenzo Manzoni
 
How I did it (in .NET): idiomatic Domain Driven Design
How I did it (in .NET): idiomatic Domain Driven DesignHow I did it (in .NET): idiomatic Domain Driven Design
How I did it (in .NET): idiomatic Domain Driven DesignAndrea Saltarello
 
2016 02-24 - Piattaforme per i Big Data
2016 02-24 - Piattaforme per i Big Data2016 02-24 - Piattaforme per i Big Data
2016 02-24 - Piattaforme per i Big DataAlberto Paro
 
Introduzione mongodb
Introduzione mongodbIntroduzione mongodb
Introduzione mongodbMarco Buttolo
 
Lezione 8 - Pratica - Il diagramma E-R
Lezione 8 - Pratica - Il diagramma E-RLezione 8 - Pratica - Il diagramma E-R
Lezione 8 - Pratica - Il diagramma E-RGiuseppe Cramarossa
 
Predisposizione di un dataset per applicazioni di natural language generation...
Predisposizione di un dataset per applicazioni di natural language generation...Predisposizione di un dataset per applicazioni di natural language generation...
Predisposizione di un dataset per applicazioni di natural language generation...StefanoFurlan9
 
Coding Day May 26th Un'architettura scalabile e modulare per il css
Coding Day May 26th Un'architettura scalabile e modulare per il cssCoding Day May 26th Un'architettura scalabile e modulare per il css
Coding Day May 26th Un'architettura scalabile e modulare per il cssVendini-Italy
 
Programmazione web libera dai framework
Programmazione web libera dai frameworkProgrammazione web libera dai framework
Programmazione web libera dai frameworkFrancesca1980
 
Layered Expression Trees feat. CQRS
Layered Expression Trees feat. CQRSLayered Expression Trees feat. CQRS
Layered Expression Trees feat. CQRSAndrea Saltarello
 

Similar a Back to Basics, webinar 3: Riflessioni sulla progettazione degli schemi nei documenti (20)

I Graph Database: analisi del comportamento degli utenti
I Graph Database: analisi del comportamento degli utentiI Graph Database: analisi del comportamento degli utenti
I Graph Database: analisi del comportamento degli utenti
 
MongoDB - Back to Basics 2017 - Introduzione a NoSQL
MongoDB - Back to Basics 2017 - Introduzione a NoSQLMongoDB - Back to Basics 2017 - Introduzione a NoSQL
MongoDB - Back to Basics 2017 - Introduzione a NoSQL
 
Entity Framework 6 for developers, Code-First!
Entity Framework 6 for developers, Code-First!Entity Framework 6 for developers, Code-First!
Entity Framework 6 for developers, Code-First!
 
MyTask
MyTaskMyTask
MyTask
 
Love Your Database (ESC 2k16)
Love Your Database (ESC 2k16)Love Your Database (ESC 2k16)
Love Your Database (ESC 2k16)
 
JSON-LD e Schema.org per il Web Semantico: SMX milano 2015
JSON-LD e Schema.org per il Web Semantico: SMX milano 2015JSON-LD e Schema.org per il Web Semantico: SMX milano 2015
JSON-LD e Schema.org per il Web Semantico: SMX milano 2015
 
JavaScript
JavaScriptJavaScript
JavaScript
 
couchbase mobile
couchbase mobilecouchbase mobile
couchbase mobile
 
What's Big Data? - Big Data Tech - 2015 - Firenze
What's Big Data? - Big Data Tech - 2015 - FirenzeWhat's Big Data? - Big Data Tech - 2015 - Firenze
What's Big Data? - Big Data Tech - 2015 - Firenze
 
Introduzione ai Big Data e alla scienza dei dati - Exploratory Data Analysis
Introduzione ai Big Data e alla scienza dei dati - Exploratory Data AnalysisIntroduzione ai Big Data e alla scienza dei dati - Exploratory Data Analysis
Introduzione ai Big Data e alla scienza dei dati - Exploratory Data Analysis
 
How I did it (in .NET): idiomatic Domain Driven Design
How I did it (in .NET): idiomatic Domain Driven DesignHow I did it (in .NET): idiomatic Domain Driven Design
How I did it (in .NET): idiomatic Domain Driven Design
 
2016 02-24 - Piattaforme per i Big Data
2016 02-24 - Piattaforme per i Big Data2016 02-24 - Piattaforme per i Big Data
2016 02-24 - Piattaforme per i Big Data
 
Introduzione mongodb
Introduzione mongodbIntroduzione mongodb
Introduzione mongodb
 
Lezione 8 - Pratica - Il diagramma E-R
Lezione 8 - Pratica - Il diagramma E-RLezione 8 - Pratica - Il diagramma E-R
Lezione 8 - Pratica - Il diagramma E-R
 
Predisposizione di un dataset per applicazioni di natural language generation...
Predisposizione di un dataset per applicazioni di natural language generation...Predisposizione di un dataset per applicazioni di natural language generation...
Predisposizione di un dataset per applicazioni di natural language generation...
 
Coding Day May 26th Un'architettura scalabile e modulare per il css
Coding Day May 26th Un'architettura scalabile e modulare per il cssCoding Day May 26th Un'architettura scalabile e modulare per il css
Coding Day May 26th Un'architettura scalabile e modulare per il css
 
Programmazione web libera dai framework
Programmazione web libera dai frameworkProgrammazione web libera dai framework
Programmazione web libera dai framework
 
Layered Expression Trees feat. CQRS
Layered Expression Trees feat. CQRSLayered Expression Trees feat. CQRS
Layered Expression Trees feat. CQRS
 
Franco Caporale Couchbase Milano
Franco Caporale Couchbase MilanoFranco Caporale Couchbase Milano
Franco Caporale Couchbase Milano
 
Introduzione a node.js
Introduzione a node.jsIntroduzione a node.js
Introduzione a node.js
 

Más de MongoDB

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump StartMongoDB
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB
 

Más de MongoDB (20)

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
 

Back to Basics, webinar 3: Riflessioni sulla progettazione degli schemi nei documenti

  • 1.
  • 2. Code MassimoB gets you a 25% discount off the list price
  • 3. Back to Basics 2016 : Webinar 3 Pensare a Documenti Massimo Brignoli Principal Solution Architect, EMEA massimo@mongodb.com @massimobrignoli
  • 4. 4 Review • Webinar 1 : Introduzione a NoSQL – Tipi di Database NoSQL – MongoDB è un database a documenti – Replica Set e Shard • Webinar 2 – Costruire una semplice applicazione – Aggiungere gli indici – Usare Explain per misurare le operazioni
  • 5. 5 Pensare a Documenti • I Documenti in MongoDB sono Javascript Objects (JSON) • Sono codificati come BSON – BSON è “Binary JSON” – BSON permette un encoding e decoding efficiente dei JSON • Richiesto per una trasmissione dati e gestione dello spazio disco efficiente. • Elimina la necessità di fare il aprsing del testo di tutti I sotto oggetti • Le specifiche si trovano su http://bsonspec.org/
  • 6. 6 Esempio di Documento { first_name: ‘Paul’, surname: ‘Miller’, cell: 447557505611, city: ‘London’, location: [45.123,47.232], Profession: [‘banking’, ‘finance’, ‘trader’], cars: [ { model: ‘Bentley’, year: 1973, value: 100000, … }, { model: ‘Rolls Royce’, year: 1965, value: 330000, … } ] } Fields can contain an array of sub-documents Fields Typed field values Fields can contain arrays
  • 7. 7 Data Store – Key Value Key 1 Value Key 1 Value Key 1 Value
  • 8. 8 Data Store - Relazionale Key 1 Value 1 Value 1 Value 1 Value 1 Key 2 Value 1 Value 1 Value 1 Value 1 Key 3 Value 1 Value 1 Value 1 Value 1 Key 4 Value 1 Value 1 Value 1 Value 1
  • 9. 9 Data Store - Documenti Key3 Key4 Key5 Value 3 Value 5 Value 4Key6 Value 5Key7 Value 2 Value 1Key1 Key1 Key1 Key2
  • 10. 10 La Forma dei Sottodocumenti { “key1” : “value 1” } { “key1” : { “key2” : “value 1”, “key3” : { “key4” : “value 3”, “key5” : “value 4” } } { “key1” : { “key6” : “value 5”, “key7” : “value 6” } }
  • 11. 11 Alcuni esempi di Query # Will find the first two documents db.demo.find( { “key1” : “value” } ) # find the second document by nested value db.demo.find( { "key1.key3.key4" : "value 3" } ) # will find the third document db.demo.find( { "key1.key6" : "value 4" } )
  • 12. 12 Modellazione e Cardinalità • One to One –Titolo al blog post • One to Many –Blog post ai commenti • One to Millions –Blog post sulle visite al sito (e.g. Huffington Post)
  • 13. 13 One To One { “Title” : “This is a blog post”, “Body” : “This is the body text of a very short blog post”, … } Possiamo indicizzare sia “Title” che “Body”.
  • 14. 14 One to Many { “Title” : “This is a blog post”, “Body” : “This is the body text”, “Comments” : [ { “name” : “Joe Drumgoole”, “email” : “Joe.Drumgoole@mongodb.com”, “comment” : “I love your writing style” }, { “name” : “John Smith”, “email” : “John.Smith@example.com”, “comment” : “I hate your writing style” }] } Se ci aspettiamo un basso numero di commenti possiamo incapsularli all’interno del documento principale
  • 15. 15 Criticità Principali • Come scrivete sul DB? –I commenti sono inseriti più frequentemente dei post. –I Commenti possono avere immagini, tags, grandi pezzi di testo • Come leggete dal DB? –I commenti possono non essere visualizzati –Possono essere mostrati in una pagina dedicata –Gli utenti raramenti leggono tutti i commenti
  • 16. 16 Approccio Alternativo: Collection Separata • Mantenere tutti I commenti in una colleciton separata • Aggiungere le referenze ai commenti come un array di ID dei commenti • Richiede due query per visualizzare il blog post e i relativi commenti • Richiede due scritture per create un commento { _id : ObjectID( “AAAA” ), name : “Massimo Brignoli”, email : “massimo@mongodb.com”, comment :“I love your writing style”, } { _id : ObjectID( “AAAB” ), name : “John Smith”, email : “Joe.Drumgoole@mongodb.com”, comment :“I hate your writing style”, } { “_id” : ObjectID( “ZZZZ” ), “Title” : “A Blog Title”, “Body” : “A blog post”, “comments” : [ ObjectID( “AAAA” ), ObjectID( “AAAB” )] } { “_id” : ObjectID( “ZZZZ” ), “Title” : “A Blog Title”, “Body” : “A blog post”, “comments” : [] }
  • 17. 17 Approccio Migliore – Un Ibrido { “_id” : ObjectID( “ZZZZ” ), “Title” : “A Blog Title”, “Body” : “A blog post”, “comments” : [{ “_id” : ObjectID( “AAAA” ) “name” : “Joe Drumgoole”, “email” : “Joe.D@mongodb.com”, comment :“I love your writing style”, } { _id : ObjectID( “AAAB” ), name : “John Smith”, email : “Joe.Drumgoole@mongodb.com”, comment :“I hate your writing style”, }] } { “_post_jd” : ObjectID( “ZZZZ” ), “comments” : [{ “_id” : ObjectID( “AAAA” ) “name” : “Joe Drumgoole”, “email” : “Joe.D@mongodb.com”, “comment” :“I love your writing style”, } {...},{...},{...},{...},{...},{...} ,{..},{...},{...},{...} ]
  • 18. 18 E la Relazione One to Millions? • Cosa succederebbe se tracciassimo la posizione del mouse per “heat tracking”? – Ogni utente genererebbe centinaia di data point per visita. – Migliaia di data points per post – Milioni di data point per sito • Invertiamo ill modello: – Memorizziamo un blog ID per evento { “post_id” : ObjectID(“ZZZZ”), “timestamp” : ISODate("2005-01-02T00:00:00Z”), “location” : [24, 34] “click” : False, }
  • 19. 19 Ma – C’e’un numero finito di eventi al secondo { post_id : ObjectID ( “ZZZZ” ), timeStamp: ISODate("2005-01-02T00:00:00Z”), events : { 0 : { 0 : { <Info> }, 1 : { <Info> }, … 99: { <Info> }}, 1 : { 0 : { <Info> }, 1 : { <Info> }, … 99: { <Info> }}, 2 : { 0 : { <Info> }, 1 : { <Info> }, … 99: { <Info> }}, 3 : { 0 : { <Info> }, 1 : { <Info> }, … 99: { <Info> }}, ... 59 :{ 0 : { <Info> }, 1 : { <Info> }, … 99: { <Info> }} }
  • 20. 20 Linee Guida • Icapsulare SEMPRE gli oggetti con relazioni one to one • Controllate gli accessi in lettura e scrittura per determinare quando spostare I dati all’esterno • Non rimanete bloccati nel pensiero di “un record” per tutto • Abbracciate la gerarchia • Pensate alla cardinalità • Gestire la crescita aggiungendo documenti non aumentando la dimensione dei documenti • Pensate bene agli indici
  • 21. 21 Prossimo Webinar : Indicizzazione Avanzata, Indici Testuali e Geografici • Il support Full text permette ad un utente di indicizzare tutto il contenuto testuale del suo database abilitando ricerche del tipo google sulla loro base dati • Gli indici geografici permettono ad un utente di memorizzare coordinate geografiche e di effettuare ricerche basate sulla prossimità tra due punti 05 Luglio 2016, 11:00 GMT.

Notas del editor

  1. Who I am, how long have I been at MongoDB.
  2. Single index. N to M is 1 to 1.
  3. Candidate keys