SlideShare ist ein Scribd-Unternehmen logo
1 von 34
MongoDBEurope2016
Old Billingsgate, London
15 November
mongodb.com/europe
Massimo Brignoli
Principal Solution Architect, EMEA
massimo@mongodb.com
@massimobrignoli
Back to Basics 2016 : Webinar 4
Indicizzazione Avanzata
Indici Geografici e Testuali
Riassunto
• Webinar 1 – Introduzione a NoSQL
– I vari tipi di database NoSQL
– Che tipo di database è MongoDB
• Webinar 2 – La nostra prima applicazione
– Creare database e collection
– Operazioni CRUD
– Indici e Explain
• Webinar 3 – Schema Design
– Schema Dinamico
– Approcci all’incapsulamento
– Esempi
Indexing
• Un modo efficiente per ricercare dei dati usando il loro valore
• Evitare scansione completa di collection
1 2 3 4 5 6 7
I Database Tradizionali Usano BTREE
• … E anche MongoDB...
Ricerche, Inserimenti, Cancellazioni in O(Log(n))
Creazione di un Indice Semplice
db.coll.createIndex( { fieldName : <Direction> } )
Nome del Database
Nome della Collection
Comando
Nome del campo(i)
da indicizzare
Ascendente: 1
Discendente: -1
Altri due tipi di Indice
• Indice Full Text
– Permette la ricerca all’interno del testo di un campo (Lucene, Solr e
Elastic Search)
• Indice Geospaziale
– Permette la ricerca per posizione geografica (e.g. tutte le persone vicino
a me)
• Questi indici non usano Btree
Indici Full Text
• Un “inverted index” di tutte le parole contenute in un singolo campo (si
può creare solo un indice full text per ogni collection)
{ “comment” : “I think your blog post is very interesting
and informative. I hope you will post more
info like this in the future” }
>> db.posts.createIndex( { “comments” : “text” } )
MongoDB Enterprise > db.posts.find( { $text: { $search : "info" }} )
{ "_id" : ObjectId(“…"), "comment" : "I think your blog post is very interesting and informative. I hope you
will post more info like this in the future" }
MongoDB Enterprise >
Parametri dell’Indice
MongoDB Enterprise > db.posts.getIndexes()
...
{
"v" : 1,
"key" : {
"_fts" : "text",
"_ftsx" : 1
},
"name" : "comment_text",
"ns" : "test.posts",
"weights" : {
"comment" : 1
},
"default_language" : "english",
"language_override" : "language",
"textIndexVersion" : 3
}
Nel Log del Server
I INDEX [conn275] build index on: test.posts properties: { v: 1, key: {
_fts: "text", _ftsx: 1 }, name: "comment_text", ns: "test.posts",
weights: { comment: 1 }, default_language: "english",
language_override: "language", textIndexVersion: 3 }}
I INDEX [conn275] building index using bulk method
I INDEX [conn275] build index done. scanned 3 total records. 0
secs
Alcuni Esempi in Dettaglio
>> db.posts.insert( { "comment" : "Red yellow orange green" } )
>> db.posts.insert( { "comment" : "Pink purple blue" } )
>> db.posts.insert( { "comment" : "Red Pink" } )
>> db.posts.find( { "$text" : { "$search" : "Red" }} )
{ "_id" : ObjectId(“…”), "comment" : "Red yellow orange green" }
{ "_id" : ObjectId( »…"), "comment" : "Red Pink" }
>> db.posts.find( { "$text" : { "$search" : "Red Green" }} )
{ "_id" : ObjectId(« …"), "comment" : "Red Pink" }
{ "_id" : ObjectId(« …"), "comment" : "Red yellow orange green" }
>> db.posts.find( { "$text" : { "$search" : "red" }} ) # <- Case Insensitve
{ "_id" : ObjectId(“…"), "comment" : "Red yellow orange green" }
{ "_id" : ObjectId(«…”), "comment" : "Red Pink" }
>>
Usare I Pesi
• Possiamo assegnare pesi diversi ai vari campi nell’indice
testuale
• Ad esempio posso voler favorire i tag rispetto ai commenti
• Quindi incremento il peso del campo tags
>> db.blog.createIndex( { comment: "text",
tags : "text” },
{ weights: { comment: 5,
tags : 10 }} )
• Ora la ricerca favorirà il campo tags
$textscore
• Possiamo usare il lo score risultante per ordinare i risultati
>> db.posts.find( { "$text" : { "$search" : "Red" }}, { score: { $meta: "textScore" }} ).sort( { score: {
$meta: "textScore" } } )
{ "_id" : …, "comment" : "hello", "tags" : "Red green orange", "score" : 6.666666666666666 }
{ "_id" : …, "comment" : "Red Pink", "score" : 3.75 }
{ "_id" : …, "comment" : "Red yellow orange green", "score" : 3.125 }
>>
Altri Parametri
• Language : Scegli la lingua che vuoi usare in ricerca, ad
esempio:
– $language : Spanish
• Abilita la ricerca case sensitive
– $caseSensitive : True (default false)
• Supporta i caratteri accentati (diacritic sensitive search ad
esempio café è diverso da cafe )
– $diacriticSensitive : True (default false)
Indici Geospaziali
Indici Geospaziali
• MongoDB supporta indici sferici 2D
• Permette ad un utente di rappresentazione una posizione
sulla terra (approssimata ad una sfera)
• Le coordinate sono memorizzate in un formato GeoJSON
• L’indice geospaziale supporta un sottoinsieme
delle operazioni GeoJSON
• L’indice è basato su una rappresentazione
QuadTree
• L’indice è basato sullo standard WGS 84
Coordinate
• Le coordinate sono rappresentate con longitudine e latitudine
• longitudine
– Misurata dal meridiano di Greenwich a Londra (0 gradi). Le posizione ad
est arrivano fino a 180 gradi, mentre quelle ad ovest si esprimono con un
numero negativo
• Latitudine
– Misurata dall’equatore verso nord e sud (da 0 a 90 nord, da 0 a -90 sud)
• Le coordinate in MongoDB sono memorizzate con l’ordine
longitutine/latitudine
• Coordinate in Google sono memorizzate invertite
Versioni dell’Indice 2DSphere
• Versione 1 : prima di MongoDB 2.4
• Versione 2 : da MongoDB 2.6 in poi
• Versione 3 : da MongoDB 3.2 in poi
• Parlaremo solo della Versione 3 in questo webinar
Creare un Indice 2DSphere
db.collection.createIndex
( { <location field> : "2dsphere" } )
• Il campo di posizione deve contenere coordinate oppure una
struttura dati GeoJSON
Esempio
>> db.test.createIndex( { loc : "2dsphere" } )
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
Output
>> db.test.getIndexes()
[
{
"v" : 1,
"key" : {
"loc" : "2dsphere"
},
"name" : "loc_2dsphere",
"ns" : "geo.test",
"2dsphereIndexVersion" : 3
}
]
>>
Usiamo una Semplice Base Dati per Sperimentare le
Query Geografiche
• Cerchiamo i ristoranti a Manhattan
• Scarichiamo I dati di due collection
– https://raw.githubusercontent.com/mongodb/docs-assets/geospatial/neighborhoods.json
– https://raw.githubusercontent.com/mongodb/docs-assets/geospatial/restaurants.json
• Importiamole dentro MongoDB invocando da shell
– mongoimport –c neighborhoods –d geo neighborhoods.json
– mongoimport –c restaurants –d geo restaurants.json
Documento dei Quartieri
MongoDB Enterprise > db.neighborhoods.findOne()
{
"_id" : ObjectId("55cb9c666c522cafdb053a1a"),
"geometry" : {
"coordinates" : [
[
[
-73.94193078816193,
40.70072523469547
],
...
[
-73.94409591260093,
40.69897295461309
],
]
"type" : "Polygon"
},
"name" : "Bedford"
}
Documento dei Ristoranti
MongoDB Enterprise > db.restaurants.findOne()
{
"_id" : ObjectId("55cba2476c522cafdb053adf"),
"location" : {
"coordinates" : [
-73.98241999999999,
40.579505
],
"type" : "Point"
},
"name" : "Riviera Caterer"
}
MongoDB Enterprise >
Per visualizzarlo su
google maps ricordatevi
di invertire le coordinate
Aggiungiamo gli Indici
MongoDB Enterprise > db.restaurants.createIndex({ location: "2dsphere" })
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
MongoDB Enterprise > db.neighborhoods.createIndex({ geometry: "2dsphere" })
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
MongoDB Enterprise >
Usiamo $geoIntersects per trovare I Quartieri
• Assumiamo di essere a -73.93414657, 40.82302903
• In quale quartiere siamo? Usiamo $geoIntersects
db.neighborhoods.findOne({ geometry:
{ $geoIntersects:
{ $geometry:
{ type: "Point",
coordinates:
[ -73.93414657,
40.82302903 ]}}}})
Risultato
{
"geometry" : {
”coordinates" : [
[
-73.9338307684026,
40.81959665747723
],
...
[
-73.93383000695911,
40.81949109558767
]
]
"type" : "Polygon"
},
"name" : "Central Harlem North-Polo Grounds"
}
Troviamo I Ristoranti a 350m
db.restaurants.find({ location:
{ $geoWithin: { $centerSphere:
[ [ -73.93414657, 40.82302903 ], 0.35 / 6378.1 ]
} } })
Distanza in KM Dividete per il raggio
della terra per
convertire in radianti
Risultati – (Projected)
{ "name" : "Gotham Stadium Tennis Center Cafe" }
{ "name" : "Chuck E. Cheese'S" }
{ "name" : "Red Star Chinese Restaurant" }
{ "name" : "Tia Melli'S Latin Kitchen" }
{ "name" : "Domino'S Pizza" }
• Senza projection
{ "_id" : ObjectId("55cba2476c522cafdb0550aa"),
"location" : { "coordinates" : [ -73.93795159999999, 40.823376 ],
"type" : "Point" },
"name" : "Domino'S Pizza" }
Riassunto delle Operazioni
• $geoIntersect: Trova aree o punti che si sovrappongono o
sono adiaicenti
• $geoWithin: Trova aree che contengono un punto
• $geoNear: Restituisce le posizioni geografiche in ordine di
distanza crescente
Riassunto
• Text Indexes : Ricerca full text su tutti I campi testo di una
collection
• Geospatial Indexes : Ricerca per posizione, per intersezione o
per distanza a partire da un punto
Prossimo Webinar : Introduzione ad Aggregation
Framework
• Consente agli sviluppatori di
– Modificare, trasformare ed estrarre dati.
– Applicare funzioni analitiche standard, dai totali e le medie fino alla
deviazione standard.
• Lo vedrete in azione su un set di dati pubblici.
19 Luglio 2016, 11:00 CET.
Back to Basics, webinar 4: Indicizzazione avanzata, indici testuali e geospaziali

Weitere ähnliche Inhalte

Was ist angesagt?

2014 it - app dev series - 04 - indicizzazione
2014   it - app dev series - 04 - indicizzazione2014   it - app dev series - 04 - indicizzazione
2014 it - app dev series - 04 - indicizzazioneMongoDB
 
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
 
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
 
Session 02 - schema design e architettura
Session 02 - schema design e architetturaSession 02 - schema design e architettura
Session 02 - schema design e architetturaMongoDB
 
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
 
MongoDB SpringFramework Meeting september 2009
MongoDB SpringFramework Meeting september 2009MongoDB SpringFramework Meeting september 2009
MongoDB SpringFramework Meeting september 2009Massimiliano 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
 
MongoDB Scala Roma SpringFramework Meeting2009
MongoDB Scala Roma SpringFramework Meeting2009MongoDB Scala Roma SpringFramework Meeting2009
MongoDB Scala Roma SpringFramework Meeting2009Massimiliano Dessì
 
Schema design - Corso base di MongoDB
Schema design - Corso base di MongoDBSchema design - Corso base di MongoDB
Schema design - Corso base di MongoDBAlberto Olla
 
MongoDb and Scala SpringFramework Meeting
MongoDb and Scala SpringFramework MeetingMongoDb and Scala SpringFramework Meeting
MongoDb and Scala SpringFramework Meetingguest67beeb9
 
Creating Highly-Available MongoDB Microservices with Docker Containers and Ku...
Creating Highly-Available MongoDB Microservices with Docker Containers and Ku...Creating Highly-Available MongoDB Microservices with Docker Containers and Ku...
Creating Highly-Available MongoDB Microservices with Docker Containers and Ku...MongoDB
 
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
 
Abusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side StorageAbusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side Storageameft
 
Scala Programming Linux Day 2009
Scala Programming Linux Day 2009Scala Programming Linux Day 2009
Scala Programming Linux Day 2009Massimiliano Dessì
 

Was ist angesagt? (14)

2014 it - app dev series - 04 - indicizzazione
2014   it - app dev series - 04 - indicizzazione2014   it - app dev series - 04 - indicizzazione
2014 it - app dev series - 04 - indicizzazione
 
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
 
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
 
Session 02 - schema design e architettura
Session 02 - schema design e architetturaSession 02 - schema design e architettura
Session 02 - schema design e architettura
 
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 SpringFramework Meeting september 2009
MongoDB SpringFramework Meeting september 2009MongoDB SpringFramework Meeting september 2009
MongoDB SpringFramework Meeting september 2009
 
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
 
MongoDB Scala Roma SpringFramework Meeting2009
MongoDB Scala Roma SpringFramework Meeting2009MongoDB Scala Roma SpringFramework Meeting2009
MongoDB Scala Roma SpringFramework Meeting2009
 
Schema design - Corso base di MongoDB
Schema design - Corso base di MongoDBSchema design - Corso base di MongoDB
Schema design - Corso base di MongoDB
 
MongoDb and Scala SpringFramework Meeting
MongoDb and Scala SpringFramework MeetingMongoDb and Scala SpringFramework Meeting
MongoDb and Scala SpringFramework Meeting
 
Creating Highly-Available MongoDB Microservices with Docker Containers and Ku...
Creating Highly-Available MongoDB Microservices with Docker Containers and Ku...Creating Highly-Available MongoDB Microservices with Docker Containers and Ku...
Creating Highly-Available MongoDB Microservices with Docker Containers and Ku...
 
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
 
Abusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side StorageAbusing HTML 5 Client-side Storage
Abusing HTML 5 Client-side Storage
 
Scala Programming Linux Day 2009
Scala Programming Linux Day 2009Scala Programming Linux Day 2009
Scala Programming Linux Day 2009
 

Andere mochten auch

Back to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentBack to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentMongoDB
 
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)MongoDB
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...MongoDB
 
Webinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to BasicsWebinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to BasicsMongoDB
 
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
 
Beyond the Basics 1: Storage Engines
Beyond the Basics 1: Storage EnginesBeyond the Basics 1: Storage Engines
Beyond the Basics 1: Storage EnginesMongoDB
 
Back to Basics Webinar 3: Schema Design Thinking in Documents
 Back to Basics Webinar 3: Schema Design Thinking in Documents Back to Basics Webinar 3: Schema Design Thinking in Documents
Back to Basics Webinar 3: Schema Design Thinking in DocumentsMongoDB
 
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
 
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial IndexesBack to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial IndexesMongoDB
 
OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialSteven Francia
 
Back to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLBack to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLMongoDB
 
Mongo db data-models guide
Mongo db data-models guideMongo db data-models guide
Mongo db data-models guideDeysi Gmarra
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsMongoDB
 
Advanced Schema Design Patterns
Advanced Schema Design PatternsAdvanced Schema Design Patterns
Advanced Schema Design PatternsMongoDB
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationMongoDB
 
Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)
Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)
Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)MongoDB
 

Andere mochten auch (17)

Back to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentBack to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production Deployment
 
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
 
Webinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to BasicsWebinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to Basics
 
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
 
Beyond the Basics 1: Storage Engines
Beyond the Basics 1: Storage EnginesBeyond the Basics 1: Storage Engines
Beyond the Basics 1: Storage Engines
 
Back to Basics Webinar 3: Schema Design Thinking in Documents
 Back to Basics Webinar 3: Schema Design Thinking in Documents Back to Basics Webinar 3: Schema Design Thinking in Documents
Back to Basics Webinar 3: Schema Design Thinking in Documents
 
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
 
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial IndexesBack to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
 
OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB Tutorial
 
Back to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLBack to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQL
 
MongoDB for Developers
MongoDB for DevelopersMongoDB for Developers
MongoDB for Developers
 
Mongo db data-models guide
Mongo db data-models guideMongo db data-models guide
Mongo db data-models guide
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
 
Advanced Schema Design Patterns
Advanced Schema Design PatternsAdvanced Schema Design Patterns
Advanced Schema Design Patterns
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
 
Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)
Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)
Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)
 

Ähnlich wie Back to Basics, webinar 4: Indicizzazione avanzata, indici testuali e geospaziali

Love Your Database (ESC 2k16)
Love Your Database (ESC 2k16)Love Your Database (ESC 2k16)
Love Your Database (ESC 2k16)PgTraining
 
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
 
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
 
SQL Server Modern Query Processing
SQL Server Modern Query ProcessingSQL Server Modern Query Processing
SQL Server Modern Query ProcessingGianluca Hotz
 
How create a single page apps using html5 and javascript
How create a single page apps using html5 and javascript How create a single page apps using html5 and javascript
How create a single page apps using html5 and javascript Stefano Marchisio
 
GWT vs CSS3
GWT vs CSS3GWT vs CSS3
GWT vs CSS3GWTcon
 
HTML5 Italy: Mai più CSS, fogli di stile moderni con LESS - Salvatore Romeo
HTML5 Italy: Mai più CSS, fogli di stile moderni con LESS - Salvatore RomeoHTML5 Italy: Mai più CSS, fogli di stile moderni con LESS - Salvatore Romeo
HTML5 Italy: Mai più CSS, fogli di stile moderni con LESS - Salvatore Romeomarcocasario
 
Layered Expression Trees feat. CQRS
Layered Expression Trees feat. CQRSLayered Expression Trees feat. CQRS
Layered Expression Trees feat. CQRSAndrea Saltarello
 
Le novita di MongoDB 3.6
Le novita di MongoDB 3.6Le novita di MongoDB 3.6
Le novita di MongoDB 3.6MongoDB
 
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
 
DotNetToscana - Sessione TypeScript
DotNetToscana - Sessione TypeScriptDotNetToscana - Sessione TypeScript
DotNetToscana - Sessione TypeScriptSinergia Totale
 
Quanto mi costa SQL Pool Serverless Synapse
Quanto mi costa SQL Pool Serverless SynapseQuanto mi costa SQL Pool Serverless Synapse
Quanto mi costa SQL Pool Serverless SynapseMarco Pozzan
 
Effective Code Transformations in C++
Effective Code Transformations in C++Effective Code Transformations in C++
Effective Code Transformations in C++Marco Arena
 
A brief intro to TDD for a JUG-TAA event
A brief intro to TDD for a JUG-TAA eventA brief intro to TDD for a JUG-TAA event
A brief intro to TDD for a JUG-TAA eventPietro Di Bello
 

Ähnlich wie Back to Basics, webinar 4: Indicizzazione avanzata, indici testuali e geospaziali (20)

Love Your Database (ESC 2k16)
Love Your Database (ESC 2k16)Love Your Database (ESC 2k16)
Love Your Database (ESC 2k16)
 
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
 
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
 
MyTask
MyTaskMyTask
MyTask
 
SQL Server Modern Query Processing
SQL Server Modern Query ProcessingSQL Server Modern Query Processing
SQL Server Modern Query Processing
 
How create a single page apps using html5 and javascript
How create a single page apps using html5 and javascript How create a single page apps using html5 and javascript
How create a single page apps using html5 and javascript
 
GWT vs CSS3
GWT vs CSS3GWT vs CSS3
GWT vs CSS3
 
Linuxday2013
Linuxday2013 Linuxday2013
Linuxday2013
 
Basi Di Dati 05
Basi Di Dati 05Basi Di Dati 05
Basi Di Dati 05
 
HTML5 Italy: Mai più CSS, fogli di stile moderni con LESS - Salvatore Romeo
HTML5 Italy: Mai più CSS, fogli di stile moderni con LESS - Salvatore RomeoHTML5 Italy: Mai più CSS, fogli di stile moderni con LESS - Salvatore Romeo
HTML5 Italy: Mai più CSS, fogli di stile moderni con LESS - Salvatore Romeo
 
Layered Expression Trees feat. CQRS
Layered Expression Trees feat. CQRSLayered Expression Trees feat. CQRS
Layered Expression Trees feat. CQRS
 
Le novita di MongoDB 3.6
Le novita di MongoDB 3.6Le novita di MongoDB 3.6
Le novita di MongoDB 3.6
 
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
 
DotNetToscana - Sessione TypeScript
DotNetToscana - Sessione TypeScriptDotNetToscana - Sessione TypeScript
DotNetToscana - Sessione TypeScript
 
Quanto mi costa SQL Pool Serverless Synapse
Quanto mi costa SQL Pool Serverless SynapseQuanto mi costa SQL Pool Serverless Synapse
Quanto mi costa SQL Pool Serverless Synapse
 
Office & VBA - Giorno 6
Office & VBA - Giorno 6Office & VBA - Giorno 6
Office & VBA - Giorno 6
 
Effective Code Transformations in C++
Effective Code Transformations in C++Effective Code Transformations in C++
Effective Code Transformations in C++
 
A brief intro to TDD for a JUG-TAA event
A brief intro to TDD for a JUG-TAA eventA brief intro to TDD for a JUG-TAA event
A brief intro to TDD for a JUG-TAA event
 
Excel development e sql 2.1
Excel development e sql   2.1Excel development e sql   2.1
Excel development e sql 2.1
 
Dojo nuovo look alle vostre applicazioni web Domino
Dojo nuovo look alle vostre applicazioni web DominoDojo nuovo look alle vostre applicazioni web Domino
Dojo nuovo look alle vostre applicazioni web Domino
 

Mehr von 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
 

Mehr von 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 4: Indicizzazione avanzata, indici testuali e geospaziali

  • 1. MongoDBEurope2016 Old Billingsgate, London 15 November mongodb.com/europe
  • 2. Massimo Brignoli Principal Solution Architect, EMEA massimo@mongodb.com @massimobrignoli Back to Basics 2016 : Webinar 4 Indicizzazione Avanzata Indici Geografici e Testuali
  • 3. Riassunto • Webinar 1 – Introduzione a NoSQL – I vari tipi di database NoSQL – Che tipo di database è MongoDB • Webinar 2 – La nostra prima applicazione – Creare database e collection – Operazioni CRUD – Indici e Explain • Webinar 3 – Schema Design – Schema Dinamico – Approcci all’incapsulamento – Esempi
  • 4. Indexing • Un modo efficiente per ricercare dei dati usando il loro valore • Evitare scansione completa di collection 1 2 3 4 5 6 7
  • 5. I Database Tradizionali Usano BTREE • … E anche MongoDB...
  • 7. Creazione di un Indice Semplice db.coll.createIndex( { fieldName : <Direction> } ) Nome del Database Nome della Collection Comando Nome del campo(i) da indicizzare Ascendente: 1 Discendente: -1
  • 8. Altri due tipi di Indice • Indice Full Text – Permette la ricerca all’interno del testo di un campo (Lucene, Solr e Elastic Search) • Indice Geospaziale – Permette la ricerca per posizione geografica (e.g. tutte le persone vicino a me) • Questi indici non usano Btree
  • 9. Indici Full Text • Un “inverted index” di tutte le parole contenute in un singolo campo (si può creare solo un indice full text per ogni collection) { “comment” : “I think your blog post is very interesting and informative. I hope you will post more info like this in the future” } >> db.posts.createIndex( { “comments” : “text” } ) MongoDB Enterprise > db.posts.find( { $text: { $search : "info" }} ) { "_id" : ObjectId(“…"), "comment" : "I think your blog post is very interesting and informative. I hope you will post more info like this in the future" } MongoDB Enterprise >
  • 10. Parametri dell’Indice MongoDB Enterprise > db.posts.getIndexes() ... { "v" : 1, "key" : { "_fts" : "text", "_ftsx" : 1 }, "name" : "comment_text", "ns" : "test.posts", "weights" : { "comment" : 1 }, "default_language" : "english", "language_override" : "language", "textIndexVersion" : 3 }
  • 11. Nel Log del Server I INDEX [conn275] build index on: test.posts properties: { v: 1, key: { _fts: "text", _ftsx: 1 }, name: "comment_text", ns: "test.posts", weights: { comment: 1 }, default_language: "english", language_override: "language", textIndexVersion: 3 }} I INDEX [conn275] building index using bulk method I INDEX [conn275] build index done. scanned 3 total records. 0 secs
  • 12. Alcuni Esempi in Dettaglio >> db.posts.insert( { "comment" : "Red yellow orange green" } ) >> db.posts.insert( { "comment" : "Pink purple blue" } ) >> db.posts.insert( { "comment" : "Red Pink" } ) >> db.posts.find( { "$text" : { "$search" : "Red" }} ) { "_id" : ObjectId(“…”), "comment" : "Red yellow orange green" } { "_id" : ObjectId( »…"), "comment" : "Red Pink" } >> db.posts.find( { "$text" : { "$search" : "Red Green" }} ) { "_id" : ObjectId(« …"), "comment" : "Red Pink" } { "_id" : ObjectId(« …"), "comment" : "Red yellow orange green" } >> db.posts.find( { "$text" : { "$search" : "red" }} ) # <- Case Insensitve { "_id" : ObjectId(“…"), "comment" : "Red yellow orange green" } { "_id" : ObjectId(«…”), "comment" : "Red Pink" } >>
  • 13. Usare I Pesi • Possiamo assegnare pesi diversi ai vari campi nell’indice testuale • Ad esempio posso voler favorire i tag rispetto ai commenti • Quindi incremento il peso del campo tags >> db.blog.createIndex( { comment: "text", tags : "text” }, { weights: { comment: 5, tags : 10 }} ) • Ora la ricerca favorirà il campo tags
  • 14. $textscore • Possiamo usare il lo score risultante per ordinare i risultati >> db.posts.find( { "$text" : { "$search" : "Red" }}, { score: { $meta: "textScore" }} ).sort( { score: { $meta: "textScore" } } ) { "_id" : …, "comment" : "hello", "tags" : "Red green orange", "score" : 6.666666666666666 } { "_id" : …, "comment" : "Red Pink", "score" : 3.75 } { "_id" : …, "comment" : "Red yellow orange green", "score" : 3.125 } >>
  • 15. Altri Parametri • Language : Scegli la lingua che vuoi usare in ricerca, ad esempio: – $language : Spanish • Abilita la ricerca case sensitive – $caseSensitive : True (default false) • Supporta i caratteri accentati (diacritic sensitive search ad esempio café è diverso da cafe ) – $diacriticSensitive : True (default false)
  • 17. Indici Geospaziali • MongoDB supporta indici sferici 2D • Permette ad un utente di rappresentazione una posizione sulla terra (approssimata ad una sfera) • Le coordinate sono memorizzate in un formato GeoJSON • L’indice geospaziale supporta un sottoinsieme delle operazioni GeoJSON • L’indice è basato su una rappresentazione QuadTree • L’indice è basato sullo standard WGS 84
  • 18. Coordinate • Le coordinate sono rappresentate con longitudine e latitudine • longitudine – Misurata dal meridiano di Greenwich a Londra (0 gradi). Le posizione ad est arrivano fino a 180 gradi, mentre quelle ad ovest si esprimono con un numero negativo • Latitudine – Misurata dall’equatore verso nord e sud (da 0 a 90 nord, da 0 a -90 sud) • Le coordinate in MongoDB sono memorizzate con l’ordine longitutine/latitudine • Coordinate in Google sono memorizzate invertite
  • 19. Versioni dell’Indice 2DSphere • Versione 1 : prima di MongoDB 2.4 • Versione 2 : da MongoDB 2.6 in poi • Versione 3 : da MongoDB 3.2 in poi • Parlaremo solo della Versione 3 in questo webinar
  • 20. Creare un Indice 2DSphere db.collection.createIndex ( { <location field> : "2dsphere" } ) • Il campo di posizione deve contenere coordinate oppure una struttura dati GeoJSON
  • 21. Esempio >> db.test.createIndex( { loc : "2dsphere" } ) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 }
  • 22. Output >> db.test.getIndexes() [ { "v" : 1, "key" : { "loc" : "2dsphere" }, "name" : "loc_2dsphere", "ns" : "geo.test", "2dsphereIndexVersion" : 3 } ] >>
  • 23. Usiamo una Semplice Base Dati per Sperimentare le Query Geografiche • Cerchiamo i ristoranti a Manhattan • Scarichiamo I dati di due collection – https://raw.githubusercontent.com/mongodb/docs-assets/geospatial/neighborhoods.json – https://raw.githubusercontent.com/mongodb/docs-assets/geospatial/restaurants.json • Importiamole dentro MongoDB invocando da shell – mongoimport –c neighborhoods –d geo neighborhoods.json – mongoimport –c restaurants –d geo restaurants.json
  • 24. Documento dei Quartieri MongoDB Enterprise > db.neighborhoods.findOne() { "_id" : ObjectId("55cb9c666c522cafdb053a1a"), "geometry" : { "coordinates" : [ [ [ -73.94193078816193, 40.70072523469547 ], ... [ -73.94409591260093, 40.69897295461309 ], ] "type" : "Polygon" }, "name" : "Bedford" }
  • 25. Documento dei Ristoranti MongoDB Enterprise > db.restaurants.findOne() { "_id" : ObjectId("55cba2476c522cafdb053adf"), "location" : { "coordinates" : [ -73.98241999999999, 40.579505 ], "type" : "Point" }, "name" : "Riviera Caterer" } MongoDB Enterprise > Per visualizzarlo su google maps ricordatevi di invertire le coordinate
  • 26. Aggiungiamo gli Indici MongoDB Enterprise > db.restaurants.createIndex({ location: "2dsphere" }) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } MongoDB Enterprise > db.neighborhoods.createIndex({ geometry: "2dsphere" }) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } MongoDB Enterprise >
  • 27. Usiamo $geoIntersects per trovare I Quartieri • Assumiamo di essere a -73.93414657, 40.82302903 • In quale quartiere siamo? Usiamo $geoIntersects db.neighborhoods.findOne({ geometry: { $geoIntersects: { $geometry: { type: "Point", coordinates: [ -73.93414657, 40.82302903 ]}}}})
  • 28. Risultato { "geometry" : { ”coordinates" : [ [ -73.9338307684026, 40.81959665747723 ], ... [ -73.93383000695911, 40.81949109558767 ] ] "type" : "Polygon" }, "name" : "Central Harlem North-Polo Grounds" }
  • 29. Troviamo I Ristoranti a 350m db.restaurants.find({ location: { $geoWithin: { $centerSphere: [ [ -73.93414657, 40.82302903 ], 0.35 / 6378.1 ] } } }) Distanza in KM Dividete per il raggio della terra per convertire in radianti
  • 30. Risultati – (Projected) { "name" : "Gotham Stadium Tennis Center Cafe" } { "name" : "Chuck E. Cheese'S" } { "name" : "Red Star Chinese Restaurant" } { "name" : "Tia Melli'S Latin Kitchen" } { "name" : "Domino'S Pizza" } • Senza projection { "_id" : ObjectId("55cba2476c522cafdb0550aa"), "location" : { "coordinates" : [ -73.93795159999999, 40.823376 ], "type" : "Point" }, "name" : "Domino'S Pizza" }
  • 31. Riassunto delle Operazioni • $geoIntersect: Trova aree o punti che si sovrappongono o sono adiaicenti • $geoWithin: Trova aree che contengono un punto • $geoNear: Restituisce le posizioni geografiche in ordine di distanza crescente
  • 32. Riassunto • Text Indexes : Ricerca full text su tutti I campi testo di una collection • Geospatial Indexes : Ricerca per posizione, per intersezione o per distanza a partire da un punto
  • 33. Prossimo Webinar : Introduzione ad Aggregation Framework • Consente agli sviluppatori di – Modificare, trasformare ed estrarre dati. – Applicare funzioni analitiche standard, dai totali e le medie fino alla deviazione standard. • Lo vedrete in azione su un set di dati pubblici. 19 Luglio 2016, 11:00 CET.

Hinweis der Redaktion

  1. Who I am, how long have I been at MongoDB.
  2. Each item in a Btree node points to a sub-tree containing elements below its key value. Insertions require a read before a write. Writes that split nodes are expensive.
  3. Effectively the depth of the tree.
  4. Production release numbering.