SlideShare une entreprise Scribd logo
1  sur  43
Télécharger pour lire hors ligne
basicsbasics
Learn all you need to know about MongoDB!
April 6, 2018
Who am I?
Juan Antonio Roy Couto
❏ MongoDB Master
❏ MongoDB DEV&DBA Certified
❏ MongoDB DBA at Grupo Undanet
❏ Email: juanroycouto@gmail.com
❏ Twitter: @juanroycouto
❏ Personal site: http://www.juanroy.es
2
❏ Advantages
❏ Concepts
❏ Products
❏ Characteristics
❏ Schema Design
❏ Data Modelling
❏ Installation Types
❏ Must Know
❏ CRUD
Agenda MongoDB Overview
3
❏ Aggregation Framework
❏ Analytics Tools
❏ Indexes
❏ Replica Set
❏ Sharded Cluster
❏ Scaling
❏ Security
❏ Python Driver Overview
❏ Resources
Advantages MongoDB Overview
❏ High Availability
❏ Data Safety
❏ Automatic Failover
❏ Scalability
4
❏ Faster development
❏ Real time analytics
❏ Better strategic decisions
❏ Reduce costs and time to
market
5
MongoDB SQL
Database Database
Collection Table
Document Row
Embedding/$lookup Join
Concepts MongoDB Overview
Products
https://www.mongodb.com/products/overview
MongoDB Overview
6
❏ Atlas (Database as a Service)
❏ Stitch (Backend as a Service)
❏ Drivers
❏ Ops & Cloud Manager
❏ Compass
❏ Hadoop & Spark connector
❏ BI connector
Characteristics MongoDB Overview
7
❏ Open Source General Purpose NoSQL
Database
❏ Document Oriented
❏ Non-Structured Data
❏ Schemaless
❏ Security (Authentication & Authorization)
❏ Schema Validation
❏ Backup & Restore
❏ Automation
❏ Encryption
❏ Geo-Location
❏ Graph processing
❏ Aggregation Framework
❏ Joins
❏ Change Streams
❏ Retryable Writes
❏ Pluggable Storage Engine API
❏ Multi-document ACID transactions on
June, 4.0 version
SQL Schema Design MongoDB Overview
8
❏ Customer Key
❏ First Name
❏ Last Name
Tables
Customers
❏ Address Key
❏ Customer Key
❏ Street
❏ Number
❏ Location
Addresses
❏ Pet Key
❏ Customer Key
❏ Type
❏ Breed
❏ Name
Pets
MongoDB Schema Design MongoDB Overview
9
Customers Collection
❏ Street
❏ Number
❏ Location
Addresses
❏ Type
❏ Breed
❏ Name
Pets
Customers Info
❏ First Name
❏ Last Name
❏ Type
❏ Breed
❏ Name
JSON Document MongoDB Overview
> db.customers.findOne()
{
"_id" : ObjectId("54131863041cd2e6181156ba"),
"date" : ISODate("2018-02-28T23:12:25Z"),
"first_name" : "Peter",
"last_name" : "Keil",
"address" : {
"street" : "C/Alcalá",
"number" : 123,
"location" : "Madrid",
},
"pets" : [
{
"type" : "Dog",
"breed" : "Airedale Terrier",
"name" : "Linda",
"location" : {
type : "Point",
coordinates : [ -5.724332, 40.959219 ]
}
},
{
"type" : "Dog",
...
}
]
}
>
10
_id
string
date
subdocument
number
array
geo-location
Data Modelling MongoDB Overview
11
1:1 Employee-Resume
❏ Access frequency
❏ Documents size
❏ Data atomicity
1:N City-Citizen
❏ Two linked collections
from N to 1
N:N Books-Authors
❏ Two collections linked via
array
1:Few Post-Comments
❏ One collection with
embedded data
Limits: 16MB/doc
Relational Approach vs Document Model MongoDB Overview
12
Relational Approach MongoDB Document Model
{
"_id" : ObjectId("54131863041cd2e6181156ba"),
"date" : ISODate("2018-02-28T23:12:25Z"),
"first_name" : "Peter",
"last_name" : "Keil",
"address" : {
"street" : "C/Alcalá",
"number" : 123,
"location" : "Madrid",
},
"pets" : [
{
"type" : "Dog",
"breed" : "Airedale Terrier",
"name" : "Linda",
"location" : {
type : "Point",
coordinates : [ -5.724332, 40.959219 ]
}
},
{
"type" : "Dog",
...
}
]
}
Installation Types - Standalone MongoDB Overview
13
MongoDB
Client
DRIVER
Client
DRIVER
Client
DRIVER
Installation Types - Replica Set MongoDB Overview
14
SecondarySecondary
Primary
Client
DRIVER
Client
DRIVER
Client
DRIVER
Replica Set
Installation Types - Sharded Cluster MongoDB Overview
15
Replica Set
Secondary
Secondary
Primary
Client
DRIVER
Client
DRIVER
Client
DRIVER
Secondary
Secondary
Primary
Secondary
Secondary
Primary
Secondary
Secondary
Primary
mongos mongos mongos
config server
config server
config server
Shard 0 Shard 1 Shard 2 Shard N-1
❏ In MongodB it’s not necessary to:
❏ Create a Database, simply use it!
❏ Create a Collection, simply insert one document on it!
❏ Predefine the schema of the collections, MongoDB it’s
schemaless
❏ Once MongoDB is running on your machine connect to your
database from the shell in this way:
$ mongo
Must Know MongoDB Overview
16
❏ Find
❏ Insert
❏ Bulk inserts for massive Data Load
❏ Update
❏ Remove
CRUD MongoDB Overview
17
# Select database
> use usalfullstack
# Select all documents on the collection
> db.<collectionName>.find().pretty()
# Select documents that match the criteria
> criteria = { <field1> : <value1>, <field2> : <value2> }
> db.<collectionName>.find( criteria)
# Filtering fields
> projection = { <field1> : 1, <field2> : 1 }
> db.<collectionName>.find({}, projection)
CRUD - Find MongoDB Overview
18
# Inserting a document with fields, arrays and subdocuments
> doc =
{ <field1> : <value1>,
<field2> : [
{ <field3> : <value3>, <field4> : <value4>, <field5> : <value5>
},
{ <field6> : <value6>, <field7> : <value7> },
{ <field8> : <value8> }
]
}
> db.<collectionName>.insert( doc)
CRUD - Insert MongoDB Overview
19
# Updating the document that match the criteria
> criteria = { <field1> : <value1 }
> new_doc = { <field2> : <value2>, <field3> : <value3> }
> db.<collectionName>.update( criteria, new_doc)
# Updating only one field of all the documents that match the criteria
> criteria = { <field1> : <value1 }
> new_value = { operator : { <field3> : <value3> } }
> db.<collectionName>.update( criteria, new_value, { multi : true })
CRUD - Update MongoDB Overview
20
CRUD - Remove MongoDB Overview
# Removing all documents that match the criteria
> criteria = { <field1> : <value1 }
> db.<collectionName>.remove( criteria)
21
Data Analytics with the
Aggregation Framework
MongoDB Overview
22
Aggregation Framework - Pipeline MongoDB Overview
23
> criteria = { $match : { <field1> : <value1> } }
> group = { $group : { "$_id" : "$<field2>",
<new_field> : { <operator> : "$<field3>" } } }
> projection = { $project : { "_id" : 0,
<new_field2>: "$_id",
<new_field3>: "$<new_field>"
}
}
> sort = { $sort : { <new_field3> : 1 } }
> pipeline = [ criteria, group, projection, sort ]
> db.<collectionName>.aggregate(pipeline)
Data analytics Tools MongoDB Overview
24
❏ Internals
❏ Aggregation Framework
❏ Map Reduce
❏ Externals
❏ Spark
❏ Hadoop
❏ Tableau (BI)
❏ ...
MongoDB Overview
25
Indexing - Types
❏ _id
❏ Single
❏ Compound
❏ Multikey
❏ Full Text
❏ GeoSpatial
❏ Hashed
MongoDB Overview
26
Indexing - Properties
❏ Unique
❏ Sparse
❏ TTL
❏ Partial
MongoDB Overview
27
Indexing - Improving Your Queries
.explain()
❏ queryPlanner
❏ executionStats
❏ allPlansExecution
Replica Set
❏ High Availability
❏ Data Safety
❏ Automatic Node Recovery
❏ Read Preference
❏ Write Concern
Replica Set
Secondary
Secondary
Primary
MongoDB Overview
28
❏ Scale out
❏ Even data distribution across all of the
shards based on a shard key
❏ A shard key range belongs to only one
shard
❏ More efficient queries (performance)
Sharded Cluster
Cluster
Shard 0 Shard 2Shard 1
A-I J-Q R-Z
MongoDB Overview
29
Sharded Cluster - Config Servers
❏ config database
❏ Metadata:
❏ Cluster shards list
❏ Data per shard (chunk ranges)
❏ ...
❏ Replica Set
MongoDB Overview
30
Replica Set
config server
config server
config server
❏ Receives client requests and returns
results.
❏ Reads the metadata and sends the
query to the necessary shard/shards.
❏ Does not store data.
❏ Keeps a cache version of the
metadata.
Sharded Cluster - mongos MongoDB Overview
31
Replica Set
DRIVER
Secondary
Secondary
Primary
Secondary
Secondary
Primary
mongos
config
server
config server
config server
Shard 0 Shard N-1
How To Scale Your App - Shard Key MongoDB Overview
32
❏ Monotonically Increasing
❏ Easy divisible❏ Randomness❏ Cardinality
How To Scale Your App
Sharding a Collection
MongoDB Overview
Shard 0 Shard 1 Shard 2 Shard 3
mongos
Client
Migrations
How To Scale Your App - Pre-Splitting MongoDB Overview
34
● Useful for storing data
directly in the shards
(massive data loads).
● Avoid bottlenecks.
● MongoDB does not need to
split or migrate chunks.
● After the split, the migration
must be finished before
data loading.
Cluster
Shard 0 Shard 2Shard 1
Chunk 1
Chunk 5
Chunk 3
Chunk 4
Chunk 2
How To Scale Your App
Tag-Aware Sharding
MongoDB Overview
35
● Tags are used when you want to pin ranges to a specific shard.
shard0
EMEA
shard1
APAC
shard2
LATAM
shard3
NORAM
Security MongoDB Overview
36
● Authentication
○ Users
○ Servers
● Authorization
○ Roles
○ Privileges (actions
over resources)
● Read-Only Views
● Encryption
● Auditing
Python Driver - CRUD MongoDB Overview
37
PyMongo Server
Finding
find find
find_one findOne
Inserting
insert_one insert
insert_many bulk
Updating
update_one update
update_many update
replace_one update
Deleting
delete_one remove
delete_many remove
Python Driver - CRUD Examples MongoDB Overview
38
$python find_one.py
El nombre de la persona leida es: Peter
find_one.py
import pymongo
from pymongo import MongoClient
try:
connMDB = MongoClient('localhost', 27017)
except Exception as e:
print 'Error de conexion a la base de datos', type(e),
e
db = connMDB.usalfullstack
personas = db.personas
persona = personas. find_one()
print 'El nombre de la persona leida es: ', persona['name']
Python Driver - CRUD Examples MongoDB Overview
39
Insert
pedro = { 'firstname':'Pedro', 'lastname':'García' }
maria = { 'firstname':'María', 'lastname':'Pérez' }
doc = [ pedro, maria ]
customers.insert_many(doc, ordered:True)
Update
customers.update_one({'_id':customer_id},
{$set:{'city':'Huelva'}})
Remove
customers.delete_one( { '_id' : customer_id } )
Python Driver - Cursors And Exceptions MongoDB Overview
40
import pymongo
import sys
from pymongo import MongoClient
connection = MongoClient('localhost',27017)
db = connection.test
customers = db.customers
query = { 'firstname' : 'Juan' }
projection = { 'city' : 1, '_id' : 0 }
try:
cursor = customers.find(query,projection)
except Exception as e:
print 'Unexpected error: ', type(e), e
for doc in cursor:
print doc['city']
Resources
41
◆ Official MongoDB Documentation
● https://docs.mongodb.org/manual/
◆ pymongo
● https://pypi.python.org/pypi/pymongo/3.6.0
◆ Install MongoDB on Linux
● https://docs.mongodb.com/manual/administration/install-on-linux/
◆ Install MongoDB on macOS
● https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/
◆ Install MongoDB on Windows
● https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/
◆ MongoDB University
● https://university.mongodb.com/
MongoDB Overview
Questions?
Questions?
42
MongoDB Overview
basicsbasics
Thank you for your attention!
basicsbasics
Learn all you need to know about MongoDB!
April 6, 2018

Contenu connexe

Tendances

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
 
Conceptos básicos. Seminario web 2: Su primera aplicación MongoDB
 Conceptos básicos. Seminario web 2: Su primera aplicación MongoDB Conceptos básicos. Seminario web 2: Su primera aplicación MongoDB
Conceptos básicos. Seminario web 2: Su primera aplicación MongoDBMongoDB
 
Advanced Schema Design Patterns
Advanced Schema Design PatternsAdvanced Schema Design Patterns
Advanced Schema Design PatternsMongoDB
 
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentosConceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentosMongoDB
 
Mongo db – document oriented database
Mongo db – document oriented databaseMongo db – document oriented database
Mongo db – document oriented databaseWojciech Sznapka
 
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
 
MongoDB Days Silicon Valley: Jumpstart: Ops/Admin 101
MongoDB Days Silicon Valley: Jumpstart: Ops/Admin 101MongoDB Days Silicon Valley: Jumpstart: Ops/Admin 101
MongoDB Days Silicon Valley: Jumpstart: Ops/Admin 101MongoDB
 
Conceptos básicos. Seminario web 5: Introducción a Aggregation Framework
Conceptos básicos. Seminario web 5: Introducción a Aggregation FrameworkConceptos básicos. Seminario web 5: Introducción a Aggregation Framework
Conceptos básicos. Seminario web 5: Introducción a Aggregation FrameworkMongoDB
 
Webinar: Best Practices for Getting Started with MongoDB
Webinar: Best Practices for Getting Started with MongoDBWebinar: Best Practices for Getting Started with MongoDB
Webinar: Best Practices for Getting Started with MongoDBMongoDB
 
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...Gianfranco Palumbo
 
Schema Design Best Practices with Buzz Moschetti
Schema Design Best Practices with Buzz MoschettiSchema Design Best Practices with Buzz Moschetti
Schema Design Best Practices with Buzz MoschettiMongoDB
 
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 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
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB Habilelabs
 
Back to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBBack to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBMongoDB
 
How To Connect Spark To Your Own Datasource
How To Connect Spark To Your Own DatasourceHow To Connect Spark To Your Own Datasource
How To Connect Spark To Your Own DatasourceMongoDB
 

Tendances (20)

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
 
Conceptos básicos. Seminario web 2: Su primera aplicación MongoDB
 Conceptos básicos. Seminario web 2: Su primera aplicación MongoDB Conceptos básicos. Seminario web 2: Su primera aplicación MongoDB
Conceptos básicos. Seminario web 2: Su primera aplicación MongoDB
 
MongoDB Basics Unileon
MongoDB Basics UnileonMongoDB Basics Unileon
MongoDB Basics Unileon
 
Advanced Schema Design Patterns
Advanced Schema Design PatternsAdvanced Schema Design Patterns
Advanced Schema Design Patterns
 
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentosConceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
 
MongoDB 101
MongoDB 101MongoDB 101
MongoDB 101
 
Mongo db – document oriented database
Mongo db – document oriented databaseMongo db – document oriented database
Mongo db – document oriented database
 
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
 
MongoDB Days Silicon Valley: Jumpstart: Ops/Admin 101
MongoDB Days Silicon Valley: Jumpstart: Ops/Admin 101MongoDB Days Silicon Valley: Jumpstart: Ops/Admin 101
MongoDB Days Silicon Valley: Jumpstart: Ops/Admin 101
 
Conceptos básicos. Seminario web 5: Introducción a Aggregation Framework
Conceptos básicos. Seminario web 5: Introducción a Aggregation FrameworkConceptos básicos. Seminario web 5: Introducción a Aggregation Framework
Conceptos básicos. Seminario web 5: Introducción a Aggregation Framework
 
MongoDB + Spring
MongoDB + SpringMongoDB + Spring
MongoDB + Spring
 
Webinar: Best Practices for Getting Started with MongoDB
Webinar: Best Practices for Getting Started with MongoDBWebinar: Best Practices for Getting Started with MongoDB
Webinar: Best Practices for Getting Started with MongoDB
 
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
How to leverage MongoDB for Big Data Analysis and Operations with MongoDB's A...
 
Schema Design Best Practices with Buzz Moschetti
Schema Design Best Practices with Buzz MoschettiSchema Design Best Practices with Buzz Moschetti
Schema Design Best Practices with Buzz Moschetti
 
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 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
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
Back to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBBack to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDB
 
Mongo db operations_v2
Mongo db operations_v2Mongo db operations_v2
Mongo db operations_v2
 
How To Connect Spark To Your Own Datasource
How To Connect Spark To Your Own DatasourceHow To Connect Spark To Your Own Datasource
How To Connect Spark To Your Own Datasource
 

Similaire à MongoDB FabLab León

MongoDB Workshop Universidad de Huelva
MongoDB Workshop Universidad de HuelvaMongoDB Workshop Universidad de Huelva
MongoDB Workshop Universidad de HuelvaJuan Antonio Roy Couto
 
Spark & Cassandra - DevFest Córdoba
Spark & Cassandra - DevFest CórdobaSpark & Cassandra - DevFest Córdoba
Spark & Cassandra - DevFest CórdobaJose Mº Muñoz
 
Mongodb intro
Mongodb introMongodb intro
Mongodb introchristkv
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)Uwe Printz
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDBElieHannouch
 
Eagle6 mongo dc revised
Eagle6 mongo dc revisedEagle6 mongo dc revised
Eagle6 mongo dc revisedMongoDB
 
Eagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational AwarenessEagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational AwarenessMongoDB
 
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
 
MongoDB Tick Data Presentation
MongoDB Tick Data PresentationMongoDB Tick Data Presentation
MongoDB Tick Data PresentationMongoDB
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongoMichael Bright
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and PythonMike Bright
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDBNorberto Leite
 
Data stores: beyond relational databases
Data stores: beyond relational databasesData stores: beyond relational databases
Data stores: beyond relational databasesJavier García Magna
 
Real-time analytics with Druid at Appsflyer
Real-time analytics with Druid at AppsflyerReal-time analytics with Druid at Appsflyer
Real-time analytics with Druid at AppsflyerMichael Spector
 
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
 
Joins and Other MongoDB 3.2 Aggregation Enhancements
Joins and Other MongoDB 3.2 Aggregation EnhancementsJoins and Other MongoDB 3.2 Aggregation Enhancements
Joins and Other MongoDB 3.2 Aggregation EnhancementsAndrew Morgan
 
Data Con LA 2022 - What's new with MongoDB 6.0 and Atlas
Data Con LA 2022 - What's new with MongoDB 6.0 and AtlasData Con LA 2022 - What's new with MongoDB 6.0 and Atlas
Data Con LA 2022 - What's new with MongoDB 6.0 and AtlasData Con LA
 
RMLL 2013 - Synchronize OpenLDAP and Active Directory with LSC
RMLL 2013 - Synchronize OpenLDAP and Active Directory with LSCRMLL 2013 - Synchronize OpenLDAP and Active Directory with LSC
RMLL 2013 - Synchronize OpenLDAP and Active Directory with LSCClément OUDOT
 
How sitecore depends on mongo db for scalability and performance, and what it...
How sitecore depends on mongo db for scalability and performance, and what it...How sitecore depends on mongo db for scalability and performance, and what it...
How sitecore depends on mongo db for scalability and performance, and what it...Antonios Giannopoulos
 

Similaire à MongoDB FabLab León (20)

MongoDB Workshop Universidad de Huelva
MongoDB Workshop Universidad de HuelvaMongoDB Workshop Universidad de Huelva
MongoDB Workshop Universidad de Huelva
 
Spark & Cassandra - DevFest Córdoba
Spark & Cassandra - DevFest CórdobaSpark & Cassandra - DevFest Córdoba
Spark & Cassandra - DevFest Córdoba
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
 
Eagle6 mongo dc revised
Eagle6 mongo dc revisedEagle6 mongo dc revised
Eagle6 mongo dc revised
 
Eagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational AwarenessEagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational Awareness
 
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
 
MongoDB Tick Data Presentation
MongoDB Tick Data PresentationMongoDB Tick Data Presentation
MongoDB Tick Data Presentation
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and Python
 
MongoDB
MongoDBMongoDB
MongoDB
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
Data stores: beyond relational databases
Data stores: beyond relational databasesData stores: beyond relational databases
Data stores: beyond relational databases
 
Real-time analytics with Druid at Appsflyer
Real-time analytics with Druid at AppsflyerReal-time analytics with Druid at Appsflyer
Real-time analytics with Druid at Appsflyer
 
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
 
Joins and Other MongoDB 3.2 Aggregation Enhancements
Joins and Other MongoDB 3.2 Aggregation EnhancementsJoins and Other MongoDB 3.2 Aggregation Enhancements
Joins and Other MongoDB 3.2 Aggregation Enhancements
 
Data Con LA 2022 - What's new with MongoDB 6.0 and Atlas
Data Con LA 2022 - What's new with MongoDB 6.0 and AtlasData Con LA 2022 - What's new with MongoDB 6.0 and Atlas
Data Con LA 2022 - What's new with MongoDB 6.0 and Atlas
 
RMLL 2013 - Synchronize OpenLDAP and Active Directory with LSC
RMLL 2013 - Synchronize OpenLDAP and Active Directory with LSCRMLL 2013 - Synchronize OpenLDAP and Active Directory with LSC
RMLL 2013 - Synchronize OpenLDAP and Active Directory with LSC
 
How sitecore depends on mongo db for scalability and performance, and what it...
How sitecore depends on mongo db for scalability and performance, and what it...How sitecore depends on mongo db for scalability and performance, and what it...
How sitecore depends on mongo db for scalability and performance, and what it...
 

Dernier

Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...kumargunjan9515
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteedamy56318795
 
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...nirzagarg
 
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...gajnagarg
 
Digital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareDigital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareGraham Ware
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...HyderabadDolls
 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...nirzagarg
 
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...Identify Customer Segments to Create Customer Offers for Each Segment - Appli...
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...ThinkInnovation
 
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With OrangePredicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With OrangeThinkInnovation
 
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...kumargunjan9515
 
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制vexqp
 
Introduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptxIntroduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptxAniqa Zai
 
Dubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls DubaiDubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls Dubaikojalkojal131
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...gajnagarg
 
Case Study 4 Where the cry of rebellion happen?
Case Study 4 Where the cry of rebellion happen?Case Study 4 Where the cry of rebellion happen?
Case Study 4 Where the cry of rebellion happen?RemarkSemacio
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...gajnagarg
 
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...HyderabadDolls
 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxronsairoathenadugay
 
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...vershagrag
 
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...nirzagarg
 

Dernier (20)

Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...Top Call Girls in Balaghat  9332606886Call Girls Advance Cash On Delivery Ser...
Top Call Girls in Balaghat 9332606886Call Girls Advance Cash On Delivery Ser...
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Rohtak [ 7014168258 ] Call Me For Genuine Models We...
 
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Latur [ 7014168258 ] Call Me For Genuine Models We ...
 
Digital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham WareDigital Transformation Playbook by Graham Ware
Digital Transformation Playbook by Graham Ware
 
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
Sonagachi * best call girls in Kolkata | ₹,9500 Pay Cash 8005736733 Free Home...
 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
 
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...Identify Customer Segments to Create Customer Offers for Each Segment - Appli...
Identify Customer Segments to Create Customer Offers for Each Segment - Appli...
 
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With OrangePredicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
Predicting HDB Resale Prices - Conducting Linear Regression Analysis With Orange
 
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
 
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
怎样办理圣地亚哥州立大学毕业证(SDSU毕业证书)成绩单学校原版复制
 
Introduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptxIntroduction to Statistics Presentation.pptx
Introduction to Statistics Presentation.pptx
 
Dubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls DubaiDubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls Dubai
 
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In bhavnagar [ 7014168258 ] Call Me For Genuine Models...
 
Case Study 4 Where the cry of rebellion happen?
Case Study 4 Where the cry of rebellion happen?Case Study 4 Where the cry of rebellion happen?
Case Study 4 Where the cry of rebellion happen?
 
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
Top profile Call Girls In dimapur [ 7014168258 ] Call Me For Genuine Models W...
 
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...
Kalyani ? Call Girl in Kolkata | Service-oriented sexy call girls 8005736733 ...
 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
 
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
💞 Safe And Secure Call Girls Agra Call Girls Service Just Call 🍑👄6378878445 🍑...
 
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
Top profile Call Girls In Begusarai [ 7014168258 ] Call Me For Genuine Models...
 

MongoDB FabLab León

  • 1. basicsbasics Learn all you need to know about MongoDB! April 6, 2018
  • 2. Who am I? Juan Antonio Roy Couto ❏ MongoDB Master ❏ MongoDB DEV&DBA Certified ❏ MongoDB DBA at Grupo Undanet ❏ Email: juanroycouto@gmail.com ❏ Twitter: @juanroycouto ❏ Personal site: http://www.juanroy.es 2
  • 3. ❏ Advantages ❏ Concepts ❏ Products ❏ Characteristics ❏ Schema Design ❏ Data Modelling ❏ Installation Types ❏ Must Know ❏ CRUD Agenda MongoDB Overview 3 ❏ Aggregation Framework ❏ Analytics Tools ❏ Indexes ❏ Replica Set ❏ Sharded Cluster ❏ Scaling ❏ Security ❏ Python Driver Overview ❏ Resources
  • 4. Advantages MongoDB Overview ❏ High Availability ❏ Data Safety ❏ Automatic Failover ❏ Scalability 4 ❏ Faster development ❏ Real time analytics ❏ Better strategic decisions ❏ Reduce costs and time to market
  • 5. 5 MongoDB SQL Database Database Collection Table Document Row Embedding/$lookup Join Concepts MongoDB Overview
  • 6. Products https://www.mongodb.com/products/overview MongoDB Overview 6 ❏ Atlas (Database as a Service) ❏ Stitch (Backend as a Service) ❏ Drivers ❏ Ops & Cloud Manager ❏ Compass ❏ Hadoop & Spark connector ❏ BI connector
  • 7. Characteristics MongoDB Overview 7 ❏ Open Source General Purpose NoSQL Database ❏ Document Oriented ❏ Non-Structured Data ❏ Schemaless ❏ Security (Authentication & Authorization) ❏ Schema Validation ❏ Backup & Restore ❏ Automation ❏ Encryption ❏ Geo-Location ❏ Graph processing ❏ Aggregation Framework ❏ Joins ❏ Change Streams ❏ Retryable Writes ❏ Pluggable Storage Engine API ❏ Multi-document ACID transactions on June, 4.0 version
  • 8. SQL Schema Design MongoDB Overview 8 ❏ Customer Key ❏ First Name ❏ Last Name Tables Customers ❏ Address Key ❏ Customer Key ❏ Street ❏ Number ❏ Location Addresses ❏ Pet Key ❏ Customer Key ❏ Type ❏ Breed ❏ Name Pets
  • 9. MongoDB Schema Design MongoDB Overview 9 Customers Collection ❏ Street ❏ Number ❏ Location Addresses ❏ Type ❏ Breed ❏ Name Pets Customers Info ❏ First Name ❏ Last Name ❏ Type ❏ Breed ❏ Name
  • 10. JSON Document MongoDB Overview > db.customers.findOne() { "_id" : ObjectId("54131863041cd2e6181156ba"), "date" : ISODate("2018-02-28T23:12:25Z"), "first_name" : "Peter", "last_name" : "Keil", "address" : { "street" : "C/Alcalá", "number" : 123, "location" : "Madrid", }, "pets" : [ { "type" : "Dog", "breed" : "Airedale Terrier", "name" : "Linda", "location" : { type : "Point", coordinates : [ -5.724332, 40.959219 ] } }, { "type" : "Dog", ... } ] } > 10 _id string date subdocument number array geo-location
  • 11. Data Modelling MongoDB Overview 11 1:1 Employee-Resume ❏ Access frequency ❏ Documents size ❏ Data atomicity 1:N City-Citizen ❏ Two linked collections from N to 1 N:N Books-Authors ❏ Two collections linked via array 1:Few Post-Comments ❏ One collection with embedded data Limits: 16MB/doc
  • 12. Relational Approach vs Document Model MongoDB Overview 12 Relational Approach MongoDB Document Model { "_id" : ObjectId("54131863041cd2e6181156ba"), "date" : ISODate("2018-02-28T23:12:25Z"), "first_name" : "Peter", "last_name" : "Keil", "address" : { "street" : "C/Alcalá", "number" : 123, "location" : "Madrid", }, "pets" : [ { "type" : "Dog", "breed" : "Airedale Terrier", "name" : "Linda", "location" : { type : "Point", coordinates : [ -5.724332, 40.959219 ] } }, { "type" : "Dog", ... } ] }
  • 13. Installation Types - Standalone MongoDB Overview 13 MongoDB Client DRIVER Client DRIVER Client DRIVER
  • 14. Installation Types - Replica Set MongoDB Overview 14 SecondarySecondary Primary Client DRIVER Client DRIVER Client DRIVER Replica Set
  • 15. Installation Types - Sharded Cluster MongoDB Overview 15 Replica Set Secondary Secondary Primary Client DRIVER Client DRIVER Client DRIVER Secondary Secondary Primary Secondary Secondary Primary Secondary Secondary Primary mongos mongos mongos config server config server config server Shard 0 Shard 1 Shard 2 Shard N-1
  • 16. ❏ In MongodB it’s not necessary to: ❏ Create a Database, simply use it! ❏ Create a Collection, simply insert one document on it! ❏ Predefine the schema of the collections, MongoDB it’s schemaless ❏ Once MongoDB is running on your machine connect to your database from the shell in this way: $ mongo Must Know MongoDB Overview 16
  • 17. ❏ Find ❏ Insert ❏ Bulk inserts for massive Data Load ❏ Update ❏ Remove CRUD MongoDB Overview 17
  • 18. # Select database > use usalfullstack # Select all documents on the collection > db.<collectionName>.find().pretty() # Select documents that match the criteria > criteria = { <field1> : <value1>, <field2> : <value2> } > db.<collectionName>.find( criteria) # Filtering fields > projection = { <field1> : 1, <field2> : 1 } > db.<collectionName>.find({}, projection) CRUD - Find MongoDB Overview 18
  • 19. # Inserting a document with fields, arrays and subdocuments > doc = { <field1> : <value1>, <field2> : [ { <field3> : <value3>, <field4> : <value4>, <field5> : <value5> }, { <field6> : <value6>, <field7> : <value7> }, { <field8> : <value8> } ] } > db.<collectionName>.insert( doc) CRUD - Insert MongoDB Overview 19
  • 20. # Updating the document that match the criteria > criteria = { <field1> : <value1 } > new_doc = { <field2> : <value2>, <field3> : <value3> } > db.<collectionName>.update( criteria, new_doc) # Updating only one field of all the documents that match the criteria > criteria = { <field1> : <value1 } > new_value = { operator : { <field3> : <value3> } } > db.<collectionName>.update( criteria, new_value, { multi : true }) CRUD - Update MongoDB Overview 20
  • 21. CRUD - Remove MongoDB Overview # Removing all documents that match the criteria > criteria = { <field1> : <value1 } > db.<collectionName>.remove( criteria) 21
  • 22. Data Analytics with the Aggregation Framework MongoDB Overview 22
  • 23. Aggregation Framework - Pipeline MongoDB Overview 23 > criteria = { $match : { <field1> : <value1> } } > group = { $group : { "$_id" : "$<field2>", <new_field> : { <operator> : "$<field3>" } } } > projection = { $project : { "_id" : 0, <new_field2>: "$_id", <new_field3>: "$<new_field>" } } > sort = { $sort : { <new_field3> : 1 } } > pipeline = [ criteria, group, projection, sort ] > db.<collectionName>.aggregate(pipeline)
  • 24. Data analytics Tools MongoDB Overview 24 ❏ Internals ❏ Aggregation Framework ❏ Map Reduce ❏ Externals ❏ Spark ❏ Hadoop ❏ Tableau (BI) ❏ ...
  • 25. MongoDB Overview 25 Indexing - Types ❏ _id ❏ Single ❏ Compound ❏ Multikey ❏ Full Text ❏ GeoSpatial ❏ Hashed
  • 26. MongoDB Overview 26 Indexing - Properties ❏ Unique ❏ Sparse ❏ TTL ❏ Partial
  • 27. MongoDB Overview 27 Indexing - Improving Your Queries .explain() ❏ queryPlanner ❏ executionStats ❏ allPlansExecution
  • 28. Replica Set ❏ High Availability ❏ Data Safety ❏ Automatic Node Recovery ❏ Read Preference ❏ Write Concern Replica Set Secondary Secondary Primary MongoDB Overview 28
  • 29. ❏ Scale out ❏ Even data distribution across all of the shards based on a shard key ❏ A shard key range belongs to only one shard ❏ More efficient queries (performance) Sharded Cluster Cluster Shard 0 Shard 2Shard 1 A-I J-Q R-Z MongoDB Overview 29
  • 30. Sharded Cluster - Config Servers ❏ config database ❏ Metadata: ❏ Cluster shards list ❏ Data per shard (chunk ranges) ❏ ... ❏ Replica Set MongoDB Overview 30 Replica Set config server config server config server
  • 31. ❏ Receives client requests and returns results. ❏ Reads the metadata and sends the query to the necessary shard/shards. ❏ Does not store data. ❏ Keeps a cache version of the metadata. Sharded Cluster - mongos MongoDB Overview 31 Replica Set DRIVER Secondary Secondary Primary Secondary Secondary Primary mongos config server config server config server Shard 0 Shard N-1
  • 32. How To Scale Your App - Shard Key MongoDB Overview 32 ❏ Monotonically Increasing ❏ Easy divisible❏ Randomness❏ Cardinality
  • 33. How To Scale Your App Sharding a Collection MongoDB Overview Shard 0 Shard 1 Shard 2 Shard 3 mongos Client Migrations
  • 34. How To Scale Your App - Pre-Splitting MongoDB Overview 34 ● Useful for storing data directly in the shards (massive data loads). ● Avoid bottlenecks. ● MongoDB does not need to split or migrate chunks. ● After the split, the migration must be finished before data loading. Cluster Shard 0 Shard 2Shard 1 Chunk 1 Chunk 5 Chunk 3 Chunk 4 Chunk 2
  • 35. How To Scale Your App Tag-Aware Sharding MongoDB Overview 35 ● Tags are used when you want to pin ranges to a specific shard. shard0 EMEA shard1 APAC shard2 LATAM shard3 NORAM
  • 36. Security MongoDB Overview 36 ● Authentication ○ Users ○ Servers ● Authorization ○ Roles ○ Privileges (actions over resources) ● Read-Only Views ● Encryption ● Auditing
  • 37. Python Driver - CRUD MongoDB Overview 37 PyMongo Server Finding find find find_one findOne Inserting insert_one insert insert_many bulk Updating update_one update update_many update replace_one update Deleting delete_one remove delete_many remove
  • 38. Python Driver - CRUD Examples MongoDB Overview 38 $python find_one.py El nombre de la persona leida es: Peter find_one.py import pymongo from pymongo import MongoClient try: connMDB = MongoClient('localhost', 27017) except Exception as e: print 'Error de conexion a la base de datos', type(e), e db = connMDB.usalfullstack personas = db.personas persona = personas. find_one() print 'El nombre de la persona leida es: ', persona['name']
  • 39. Python Driver - CRUD Examples MongoDB Overview 39 Insert pedro = { 'firstname':'Pedro', 'lastname':'García' } maria = { 'firstname':'María', 'lastname':'Pérez' } doc = [ pedro, maria ] customers.insert_many(doc, ordered:True) Update customers.update_one({'_id':customer_id}, {$set:{'city':'Huelva'}}) Remove customers.delete_one( { '_id' : customer_id } )
  • 40. Python Driver - Cursors And Exceptions MongoDB Overview 40 import pymongo import sys from pymongo import MongoClient connection = MongoClient('localhost',27017) db = connection.test customers = db.customers query = { 'firstname' : 'Juan' } projection = { 'city' : 1, '_id' : 0 } try: cursor = customers.find(query,projection) except Exception as e: print 'Unexpected error: ', type(e), e for doc in cursor: print doc['city']
  • 41. Resources 41 ◆ Official MongoDB Documentation ● https://docs.mongodb.org/manual/ ◆ pymongo ● https://pypi.python.org/pypi/pymongo/3.6.0 ◆ Install MongoDB on Linux ● https://docs.mongodb.com/manual/administration/install-on-linux/ ◆ Install MongoDB on macOS ● https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/ ◆ Install MongoDB on Windows ● https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/ ◆ MongoDB University ● https://university.mongodb.com/ MongoDB Overview
  • 43. basicsbasics Thank you for your attention! basicsbasics Learn all you need to know about MongoDB! April 6, 2018