SlideShare a Scribd company logo
1 of 18
Download to read offline
BIO
Senior SW Engineer
@RAI Radiotelevisione italiana
Rome, Italy

QUIT IT APP
@quititapp

GET IN TOUCH!
roberto.belardo@gmail.com	
  
	
  
@robertobelardo	
  
	
  
robertobelardo.wordpress.com	
  
	
  
Skype:	
  backslash451	
  
Traditional RDBMS
ACID (atomicity, Consistency, Isolation, Durability)
Great for relation data
widely adopted and well understood
TRANSACTIONS
JOINS
but…
• 
• 
• 
• 

joins are slow
do not scale easily
SQL is a pain in the ass -> ORM
SCHema are not flexible
- and -
NOSQL DB
ONLY

• 
• 
• 
• 

ACID-LESS (NOT ALWAYS SWEET)
Elastic scaling
Big data
Flexible data models

KEY/VALUE STORES
memcached db
project voldemort
redis
dynamo

DOCUMENT DB
mongo db
couch base

GRAPH STORES
neo4j
orient db
allegro
virtuoso

wide column stores
big table
hbase
accumulo
cassandra
mongo features
• 
• 
• 
• 
• 

Schema-less
bson document (binary json)
full index support
replication and high availability
Easy to use
Jargon
RDBMS	
  

mongoDB	
  

Table	
  

Collec=on	
  

Row(s)	
  

(JSON)	
  Document	
  

Column	
  

Field	
  

Index	
  

Index	
  

Join	
  

Embedding	
  &	
  Linking	
  

Par==on	
  

Shard	
  

GROUP	
  BY	
  

Aggrega=on	
  
Data SNIPPET
{“_id”: !ObjectId(“4dfa6baa9c65dae09a4bbda5”),!
“title”: “Programming in Scala”,!
“author”: [!
!{!
! !“first_name”:
! !“Martin”,!
! !“last_name”: ! !“Odersky”,!
! !“nationality”: !“DE”,!
! !“year_of_birth”:
!1958!
!},!
!{!
! !“first_name”:
! !“Lex”,!
! !“last_name”: ! !“Spoon”!
!},!
!{!
! !“first_name”:
! !“Bill”,!
! !“last_name”: ! !“Venners”!
!}!
]}!
CRUD querying
INSERT	
  a	
  document	
  in	
  a	
  collec7on	
  
> db.foo.insert({name:”Sauron”, type:”bad-ass”, address:”Mordor”, eyes:1})!

SELECT	
  all	
  documents	
  in	
  a	
  collec7on	
  
> db.foo.find()!

SELECT	
  some	
  documents	
  in	
  a	
  collec7on	
  
> db.foo.find({eyes:1})

> db.foo.find({eyes:1, type:”bad-ass”})!

UPDATE	
  a	
  document	
  in	
  a	
  collec7on	
  
> db.foo.save({_id:10, name:”Sauron”, type:”good boy”})!
> db.foo.update({type:”bad-ass”},{$inc:{eyes:1}},{multi:true})!

DELETE	
  all	
  documents	
  in	
  a	
  collec7on	
  
> db.foo.remove()!

DELETE	
  some	
  documents	
  in	
  a	
  collec7on	
  
> db.foo.remove({eyes:1})!
Advanced
STUFF
WRITE CONCERNS

“Specifies	
  where	
  a	
  write	
  (insert)	
  opera3on	
  has	
  succeeded.”	
  
“In	
  some	
  failure	
  cases,	
  write	
  opera3ons	
  issued	
  with	
  weak	
  write	
  concerns	
  may	
  not	
  persist.”	
  

weak concern fast writes

“With	
  stronger	
  write	
  concerns,	
  clients	
  wait	
  aAer	
  sending	
  a	
  write	
  opera3on	
  for	
  MongoDB	
  to	
  
conrm	
  the	
  write	
  opera3on.”	
  

errors ignored w:-1

It	
  does	
  not	
  acknowledge	
  write	
  op.	
  and	
  the	
  client	
  cannot	
  detect	
  failed	
  write	
  op.	
  

unacknowledged w:0

It	
  does	
  not	
  acknowledge	
  write	
  op.	
  but	
  driver	
  aUempt	
  to	
  handle	
  network	
  errors.	
  

acknowledged w:1

It	
  conrms	
  the	
  receipt	
  of	
  the	
  write	
  op.	
  allowing	
  clients	
  to	
  catch	
  errors.	
  

journaled w:1,j:true

It	
  conrms	
  the	
  receipt	
  of	
  the	
  write	
  op.	
  only	
  aWer	
  commiXng	
  the	
  data	
  to	
  journal.	
  

replica acknowledged w:n (n>1)

It	
  conrms	
  the	
  receipt	
  of	
  the	
  write	
  op.	
  	
  aWer	
  acknowledging	
  primary	
  and	
  n-­‐1	
  secondaries.	
  

DEFAULT	
  
INDEXES

Without	
  indexes,	
  mongoDB	
  must	
  scan	
  every	
  document	
  in	
  a	
  collec3on!	
  
index types

Default _ID
single field
compound index
multikey index
geospatial index
text indexes
hashed indexes
properties

unique indexes
sparse indexes

creating indexes
> db.foo.ensureIndex({phone-number:1}) !
!
> db.foo.ensureIndex({name:1, phone-number:1})!
!
> db.foo.ensureIndex({name:1}, {unique:true})!

> db.foo.ensureIndex({nickname:1}, {sparse:true})!
!
> db.foo.ensureIndex({a:1},{unique:true,sparse:true})!
REPLICAtion

Replica3on	
  provides	
  redundancy	
  and	
  increases	
  data	
  availability.	
  

Automatic failover: ELECTIONS
SHARDING
horizontal scaling the mongoway

SHARDimmutable
KEYs
shard key is

{

range based sharding
hash based sharding

. easily divisible among shards
. high degree of randomness
. targets a single shard
. compound shard key

> db.runCommand({ shardcollection:”test.users”, !
!
!
!
!
!key: { email:1}})!

split--ting
triggered automatically by a mongos if a chunk goes
beyond max size (default 64mb)

Balanc

ing

triggered automatically by a mongos if there is a chunk
imbalance (8+ chunks)
Aggre | gation

MaP
Reduce

framework

operators

. filter
. project
. unwind
. group
. sort
. limit

> db.article.aggregate(!
!{ $project: {author:1, tags: 1}},!
!{ $unwind: “$tags”},!
!{ $group: { !_id: “$tags”, !
!
!
!
!authors: { $addToSet: “$author”}}})!

{ “result”:
!{“_id”:
!{“_id”:
!{“_id”:
!{“_id”:
!],!
!“ok”:1!
}!

[!
“art”, “authors”:[“bill”, “bob”]},!
“sports”, “authors”:[“jane”, “bob”]},!
“food”, “authors”:[“jane”, “bob”]},!
“science”, “authors”:[“jane”, “bob”, “bill”]},!
still a lot to cover!
map reduce
geo spatial
GRID FS
drivers
etc….
resources
hBp://www.mongodb.org/	
  
hBp://www.mongodb.com/learn/nosql	
  
hBp://www.mongodb.org/about/introduc7on/	
  
hBp://try.mongodb.org/	
  
hBp://www.slideshare.net/spacemonkeylabs/data-­‐as-­‐documents-­‐overview-­‐and-­‐intro-­‐
to-­‐mongodb	
  
•  hBps://speakerdeck.com/backslash451	
  
•  hBps://educa7on.mongodb.com/	
  
•  hBp://lmgQy.com/?q=mongoDB	
  
• 
• 
• 
• 
• 

More Related Content

Similar to Introduction to NoSQL db and mongoDB

The RDBMS You Should Be Using
The RDBMS You Should Be UsingThe RDBMS You Should Be Using
The RDBMS You Should Be UsingColdFusionConference
 
44spotkaniePLSSUGWRO_CoNowegowKrainieChmur
44spotkaniePLSSUGWRO_CoNowegowKrainieChmur44spotkaniePLSSUGWRO_CoNowegowKrainieChmur
44spotkaniePLSSUGWRO_CoNowegowKrainieChmurTobias Koprowski
 
2011-12-13 NoSQL aus der Praxis
2011-12-13 NoSQL aus der Praxis2011-12-13 NoSQL aus der Praxis
2011-12-13 NoSQL aus der PraxisJohannes Hoppe
 
Experience sql server on l inux and docker
Experience sql server on l inux and dockerExperience sql server on l inux and docker
Experience sql server on l inux and dockerBob Ward
 
Erlang as a cloud citizen, a fractal approach to throughput
Erlang as a cloud citizen, a fractal approach to throughputErlang as a cloud citizen, a fractal approach to throughput
Erlang as a cloud citizen, a fractal approach to throughputPaolo Negri
 
Erlang and the Cloud: A Fractal Approach to Throughput
Erlang and the Cloud: A Fractal Approach to ThroughputErlang and the Cloud: A Fractal Approach to Throughput
Erlang and the Cloud: A Fractal Approach to ThroughputWooga
 
Erlang as a Cloud Citizen
Erlang as a Cloud CitizenErlang as a Cloud Citizen
Erlang as a Cloud CitizenWooga
 
SQL Azure Dec 2010 Update
SQL Azure Dec 2010 UpdateSQL Azure Dec 2010 Update
SQL Azure Dec 2010 UpdateEric Nelson
 
SQL Azure Dec Update
SQL Azure Dec UpdateSQL Azure Dec Update
SQL Azure Dec UpdateEric Nelson
 
Couchbase - Yet Another Introduction
Couchbase - Yet Another IntroductionCouchbase - Yet Another Introduction
Couchbase - Yet Another IntroductionKelum Senanayake
 
Brk2051 sql server on linux and docker
Brk2051 sql server on linux and dockerBrk2051 sql server on linux and docker
Brk2051 sql server on linux and dockerBob Ward
 
NoSql Databases
NoSql DatabasesNoSql Databases
NoSql DatabasesNimat Khattak
 
From 0 to syncing
From 0 to syncingFrom 0 to syncing
From 0 to syncingPhilipp Fehre
 
Azure Cosmos DB - NoSQL Strikes Back (An introduction to the dark side of you...
Azure Cosmos DB - NoSQL Strikes Back (An introduction to the dark side of you...Azure Cosmos DB - NoSQL Strikes Back (An introduction to the dark side of you...
Azure Cosmos DB - NoSQL Strikes Back (An introduction to the dark side of you...Andre Essing
 
NoSQL
NoSQLNoSQL
NoSQLdbulic
 
Dropping ACID: Wrapping Your Mind Around NoSQL Databases
Dropping ACID: Wrapping Your Mind Around NoSQL DatabasesDropping ACID: Wrapping Your Mind Around NoSQL Databases
Dropping ACID: Wrapping Your Mind Around NoSQL DatabasesKyle Banerjee
 
Azure doc db (slideshare)
Azure doc db (slideshare)Azure doc db (slideshare)
Azure doc db (slideshare)David Green
 
MongoDB - General Purpose Database
MongoDB - General Purpose DatabaseMongoDB - General Purpose Database
MongoDB - General Purpose DatabaseAshnikbiz
 

Similar to Introduction to NoSQL db and mongoDB (20)

The RDBMS You Should Be Using
The RDBMS You Should Be UsingThe RDBMS You Should Be Using
The RDBMS You Should Be Using
 
How and when to use NoSQL
How and when to use NoSQLHow and when to use NoSQL
How and when to use NoSQL
 
44spotkaniePLSSUGWRO_CoNowegowKrainieChmur
44spotkaniePLSSUGWRO_CoNowegowKrainieChmur44spotkaniePLSSUGWRO_CoNowegowKrainieChmur
44spotkaniePLSSUGWRO_CoNowegowKrainieChmur
 
2011-12-13 NoSQL aus der Praxis
2011-12-13 NoSQL aus der Praxis2011-12-13 NoSQL aus der Praxis
2011-12-13 NoSQL aus der Praxis
 
Experience sql server on l inux and docker
Experience sql server on l inux and dockerExperience sql server on l inux and docker
Experience sql server on l inux and docker
 
Erlang as a cloud citizen, a fractal approach to throughput
Erlang as a cloud citizen, a fractal approach to throughputErlang as a cloud citizen, a fractal approach to throughput
Erlang as a cloud citizen, a fractal approach to throughput
 
Erlang and the Cloud: A Fractal Approach to Throughput
Erlang and the Cloud: A Fractal Approach to ThroughputErlang and the Cloud: A Fractal Approach to Throughput
Erlang and the Cloud: A Fractal Approach to Throughput
 
Erlang as a Cloud Citizen
Erlang as a Cloud CitizenErlang as a Cloud Citizen
Erlang as a Cloud Citizen
 
SQL Azure Dec 2010 Update
SQL Azure Dec 2010 UpdateSQL Azure Dec 2010 Update
SQL Azure Dec 2010 Update
 
SQL Azure Dec Update
SQL Azure Dec UpdateSQL Azure Dec Update
SQL Azure Dec Update
 
Couchbase - Yet Another Introduction
Couchbase - Yet Another IntroductionCouchbase - Yet Another Introduction
Couchbase - Yet Another Introduction
 
Brk2051 sql server on linux and docker
Brk2051 sql server on linux and dockerBrk2051 sql server on linux and docker
Brk2051 sql server on linux and docker
 
NoSql Databases
NoSql DatabasesNoSql Databases
NoSql Databases
 
Azure CosmosDB - TDC2018 Florianopolis
Azure CosmosDB - TDC2018 FlorianopolisAzure CosmosDB - TDC2018 Florianopolis
Azure CosmosDB - TDC2018 Florianopolis
 
From 0 to syncing
From 0 to syncingFrom 0 to syncing
From 0 to syncing
 
Azure Cosmos DB - NoSQL Strikes Back (An introduction to the dark side of you...
Azure Cosmos DB - NoSQL Strikes Back (An introduction to the dark side of you...Azure Cosmos DB - NoSQL Strikes Back (An introduction to the dark side of you...
Azure Cosmos DB - NoSQL Strikes Back (An introduction to the dark side of you...
 
NoSQL
NoSQLNoSQL
NoSQL
 
Dropping ACID: Wrapping Your Mind Around NoSQL Databases
Dropping ACID: Wrapping Your Mind Around NoSQL DatabasesDropping ACID: Wrapping Your Mind Around NoSQL Databases
Dropping ACID: Wrapping Your Mind Around NoSQL Databases
 
Azure doc db (slideshare)
Azure doc db (slideshare)Azure doc db (slideshare)
Azure doc db (slideshare)
 
MongoDB - General Purpose Database
MongoDB - General Purpose DatabaseMongoDB - General Purpose Database
MongoDB - General Purpose Database
 

Recently uploaded

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervĂŠ Boutemy
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Recently uploaded (20)

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

Introduction to NoSQL db and mongoDB

  • 1.
  • 2. BIO Senior SW Engineer @RAI Radiotelevisione italiana Rome, Italy QUIT IT APP @quititapp GET IN TOUCH! roberto.belardo@gmail.com     @robertobelardo     robertobelardo.wordpress.com     Skype:  backslash451  
  • 3. Traditional RDBMS ACID (atomicity, Consistency, Isolation, Durability) Great for relation data widely adopted and well understood TRANSACTIONS JOINS
  • 4. but… •  •  •  •  joins are slow do not scale easily SQL is a pain in the ass -> ORM SCHema are not flexible - and -
  • 5. NOSQL DB ONLY •  •  •  •  ACID-LESS (NOT ALWAYS SWEET) Elastic scaling Big data Flexible data models KEY/VALUE STORES memcached db project voldemort redis dynamo DOCUMENT DB mongo db couch base GRAPH STORES neo4j orient db allegro virtuoso wide column stores big table hbase accumulo cassandra
  • 6.
  • 7. mongo features •  •  •  •  •  Schema-less bson document (binary json) full index support replication and high availability Easy to use
  • 8. Jargon RDBMS   mongoDB   Table   Collec=on   Row(s)   (JSON)  Document   Column   Field   Index   Index   Join   Embedding  &  Linking   Par==on   Shard   GROUP  BY   Aggrega=on  
  • 9. Data SNIPPET {“_id”: !ObjectId(“4dfa6baa9c65dae09a4bbda5”),! “title”: “Programming in Scala”,! “author”: [! !{! ! !“first_name”: ! !“Martin”,! ! !“last_name”: ! !“Odersky”,! ! !“nationality”: !“DE”,! ! !“year_of_birth”: !1958! !},! !{! ! !“first_name”: ! !“Lex”,! ! !“last_name”: ! !“Spoon”! !},! !{! ! !“first_name”: ! !“Bill”,! ! !“last_name”: ! !“Venners”! !}! ]}!
  • 10. CRUD querying INSERT  a  document  in  a  collec7on   > db.foo.insert({name:”Sauron”, type:”bad-ass”, address:”Mordor”, eyes:1})! SELECT  all  documents  in  a  collec7on   > db.foo.find()! SELECT  some  documents  in  a  collec7on   > db.foo.find({eyes:1})
 > db.foo.find({eyes:1, type:”bad-ass”})! UPDATE  a  document  in  a  collec7on   > db.foo.save({_id:10, name:”Sauron”, type:”good boy”})! > db.foo.update({type:”bad-ass”},{$inc:{eyes:1}},{multi:true})! DELETE  all  documents  in  a  collec7on   > db.foo.remove()! DELETE  some  documents  in  a  collec7on   > db.foo.remove({eyes:1})!
  • 12. WRITE CONCERNS “Species  where  a  write  (insert)  opera3on  has  succeeded.”   “In  some  failure  cases,  write  opera3ons  issued  with  weak  write  concerns  may  not  persist.”   weak concern fast writes “With  stronger  write  concerns,  clients  wait  aAer  sending  a  write  opera3on  for  MongoDB  to   conrm  the  write  opera3on.”   errors ignored w:-1 It  does  not  acknowledge  write  op.  and  the  client  cannot  detect  failed  write  op.   unacknowledged w:0 It  does  not  acknowledge  write  op.  but  driver  aUempt  to  handle  network  errors.   acknowledged w:1 It  conrms  the  receipt  of  the  write  op.  allowing  clients  to  catch  errors.   journaled w:1,j:true It  conrms  the  receipt  of  the  write  op.  only  aWer  commiXng  the  data  to  journal.   replica acknowledged w:n (n>1) It  conrms  the  receipt  of  the  write  op.    aWer  acknowledging  primary  and  n-­‐1  secondaries.   DEFAULT  
  • 13. INDEXES Without  indexes,  mongoDB  must  scan  every  document  in  a  collec3on!   index types Default _ID single field compound index multikey index geospatial index text indexes hashed indexes properties unique indexes sparse indexes creating indexes > db.foo.ensureIndex({phone-number:1}) ! ! > db.foo.ensureIndex({name:1, phone-number:1})! ! > db.foo.ensureIndex({name:1}, {unique:true})! > db.foo.ensureIndex({nickname:1}, {sparse:true})! ! > db.foo.ensureIndex({a:1},{unique:true,sparse:true})!
  • 14. REPLICAtion Replica3on  provides  redundancy  and  increases  data  availability.   Automatic failover: ELECTIONS
  • 15. SHARDING horizontal scaling the mongoway SHARDimmutable KEYs shard key is { range based sharding hash based sharding . easily divisible among shards . high degree of randomness . targets a single shard . compound shard key > db.runCommand({ shardcollection:”test.users”, ! ! ! ! ! !key: { email:1}})! split--ting triggered automatically by a mongos if a chunk goes beyond max size (default 64mb) Balanc ing triggered automatically by a mongos if there is a chunk imbalance (8+ chunks)
  • 16. Aggre | gation MaP Reduce framework operators . filter . project . unwind . group . sort . limit > db.article.aggregate(! !{ $project: {author:1, tags: 1}},! !{ $unwind: “$tags”},! !{ $group: { !_id: “$tags”, ! ! ! ! !authors: { $addToSet: “$author”}}})! { “result”: !{“_id”: !{“_id”: !{“_id”: !{“_id”: !],! !“ok”:1! }! [! “art”, “authors”:[“bill”, “bob”]},! “sports”, “authors”:[“jane”, “bob”]},! “food”, “authors”:[“jane”, “bob”]},! “science”, “authors”:[“jane”, “bob”, “bill”]},!
  • 17. still a lot to cover! map reduce geo spatial GRID FS drivers etc….
  • 18. resources hBp://www.mongodb.org/   hBp://www.mongodb.com/learn/nosql   hBp://www.mongodb.org/about/introduc7on/   hBp://try.mongodb.org/   hBp://www.slideshare.net/spacemonkeylabs/data-­‐as-­‐documents-­‐overview-­‐and-­‐intro-­‐ to-­‐mongodb   •  hBps://speakerdeck.com/backslash451   •  hBps://educa7on.mongodb.com/   •  hBp://lmgQy.com/?q=mongoDB   •  •  •  •  •