SlideShare a Scribd company logo
1 of 43
Download to read offline
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

More Related Content

What's hot

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
 

What's hot (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
 

Similar to 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
 

Similar to 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...
 

Recently uploaded

Heart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectHeart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectBoston Institute of Analytics
 
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfPredicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfBoston Institute of Analytics
 
detection and classification of knee osteoarthritis.pptx
detection and classification of knee osteoarthritis.pptxdetection and classification of knee osteoarthritis.pptx
detection and classification of knee osteoarthritis.pptxAleenaJamil4
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfJohn Sterrett
 
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理e4aez8ss
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.natarajan8993
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdfHuman37
 
Defining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryDefining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryJeremy Anderson
 
Real-Time AI Streaming - AI Max Princeton
Real-Time AI  Streaming - AI Max PrincetonReal-Time AI  Streaming - AI Max Princeton
Real-Time AI Streaming - AI Max PrincetonTimothy Spann
 
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...Thomas Poetter
 
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...ssuserf63bd7
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Colleen Farrelly
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFAAndrei Kaleshka
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...Boston Institute of Analytics
 
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degreeyuu sss
 
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degreeyuu sss
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 217djon017
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxMike Bennett
 

Recently uploaded (20)

Heart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectHeart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis Project
 
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfPredicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
 
detection and classification of knee osteoarthritis.pptx
detection and classification of knee osteoarthritis.pptxdetection and classification of knee osteoarthritis.pptx
detection and classification of knee osteoarthritis.pptx
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdf
 
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf
 
Defining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data StoryDefining Constituents, Data Vizzes and Telling a Data Story
Defining Constituents, Data Vizzes and Telling a Data Story
 
Real-Time AI Streaming - AI Max Princeton
Real-Time AI  Streaming - AI Max PrincetonReal-Time AI  Streaming - AI Max Princeton
Real-Time AI Streaming - AI Max Princeton
 
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
Minimizing AI Hallucinations/Confabulations and the Path towards AGI with Exa...
 
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
Statistics, Data Analysis, and Decision Modeling, 5th edition by James R. Eva...
 
Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFA
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
 
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
 
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptx
 

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