SlideShare a Scribd company logo
{

}

name : ‘Marcelo Cenerino’,
company: ‘Amil’,
date : ‘2013-10-30T08:30:00.000Z’
What is MongoDB?
Here’s a definition:
MongoDB (from humongous) is an open-source, highperformance, scalable, general purpose database. It is

used by organizations of all sizes to power online
applications where low latency and high availability are
critical requirements of the system.
You can have at most two of these properties for
any shared-data system. Dr. Eric A. Brewer, 2000
Main characteristics
• Document based

• Schemaless
• Open source (on GitHub)

• High performance
• Horizontally scalable
• Full featured
Customers

eBay, Ericsson, EA, SAP, Telefonica, Code School, Abril...
MongoDB vs. RDBMS
RDBMS: data is structured as tables
id

nome

idade

genero

1

João

25

Masculino

2

Maria

30

Feminino

3

Pedro

40

Masculino

...

...
...
Document oriented???
Document oriented
{
_id : 1,
nome : 'João',
idade : 25,
genero : 'Masculino'
}
MongoDB stores data as document in a
binary representation called BSON
(Binary JSON)

Size: up to 16 MB
RDBMS

vs.

MongoDB

Table

Collection

Row

Document

Column

Field

Index

Index

Joins

Embedded doc.

FK

Reference

Partition

Shard
Transaction Model

MongoDB guarantees atomic updates
to data at the document level.
Relational schema design
Relational schema design
• Large ERD diagrams

• Create table statements
• ORM to map tables to objects
• Tables just to join tables together
• Lots of revision and alter table statements until we
get it just right
In a MongoDB based app we

start building our app
and let the schema evolve.
Mongo “schema” design
Article

User
name
email

title
date
text
author

Comment[]
author
date
text

Tag[]
value
Getting started with
MongoDB
Talk MongoDB - Amil
> mongod

> mongo
Basic CRUD operations
Inserting a document
> user = {name : ‘marcelo’, age : 29, gender : ‘Male’}
> db.users.insert(user)
>

• No collection creation needed!
Querying a document
> db.users.findOne()
{
"_id" : ObjectId("5269d66271de67aa7c3c41b4"),
"name" : “marcelo",
"age" : 29,
“gender" : “male"
}

•
•
•
•

_id is the primary key in MongoDB
Automatically indexed
Automatically created as an ObjectId if not provided
Any unique immutable value could be used
Querying a document
> db.users.find({name : 'maria', age : {$gt : 25}})
{ "_id" : ObjectId("526f1af1dac0a62cdc152a96"), "name" : "maria", "age"
: 26 }
Operators
Group

Operators

Comparison

$gt, $gte, $in, $lt, $lte, $ne, $nin

Logical

$or, $and, $not, $nor

Element

$exists, $type

Evaluation

$mod, $regex, $where

Geospatial

$geoWithin, $geoIntersects, $near, $nearSphere

Array

$all, $elemMatch, $size

Projection

$, $elemMatch, $slice
Updating a document
> db.users.find({age : {$gt : 25}}, {_id : 0})
{ "name" : "maria", "age" : 26 }
{ "name" : "marcelo", "age" : 29 }
>
>db.users.update({age : {$gt : 25}}, {$set : {roles : ['admin', 'dev', 'operator']}})
Removing a document
> db.users.remove({name : 'maria'})
> db.users.find().pretty()
{
"_id" : ObjectId("526f1cb3dac0a62cdc152a98"),
"age" : 29,
"name" : "marcelo",

"roles" : [
"admin",
"dev",
"operator"

]
}
Indexing
Querying a large collection without index
> db.estabelecimentos.count()
307929
>
> db.estabelecimentos.find({'localizacao.cidade' : 'PIACATU'}).explain()
{
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : 5,
"nscannedObjects" : 307929,
"nscanned" : 307929,
"nscannedObjectsAllPlans" : 307929,
"nscannedAllPlans" : 307929,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 1,
"nChunkSkips" : 0,
"millis" : 311,
"indexBounds" : {

}
>

},
"server" : "Cenerino-PC:27017"
Showing collection’s indexes
> db.estabelecimentos.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "mapa-servicos.estabelecimentos",
"name" : "_id_"
}
]
>
Creating an index
> // creating an index
> db.estabelecimentos.ensureIndex({'localizacao.cidade' : 1})
> db.estabelecimentos.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "mapa-servicos.estabelecimentos",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"localizacao.cidade" : 1
},
"ns" : "mapa-servicos.estabelecimentos",
"name" : "localizacao.cidade_1"
}
]
>
Same query, now using index
> db.estabelecimentos.find({'localizacao.cidade' : 'PIACATU'}).explain()
{
"cursor" : "BtreeCursor localizacao.cidade_1",
"isMultiKey" : false,
"n" : 5,
"nscannedObjects" : 5,
"nscanned" : 5,
"nscannedObjectsAllPlans" : 5,
"nscannedAllPlans" : 5,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" : {
"localizacao.cidade" : [
[
"PIACATU",
"PIACATU"
]
]
},
"server" : "Cenerino-PC:27017"
}
Geospatial index
> db.estabelecimentos.ensureIndex({'localizacao.coordenadas' : '2dsphere'})
> db.estabelecimentos.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"ns" : "mapa-servicos.estabelecimentos",
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"localizacao.cidade" : 1
},
"ns" : "mapa-servicos.estabelecimentos",
"name" : "localizacao.cidade_1"
},
{
"v" : 1,
"key" : {
"localizacao.coordenadas" : "2dsphere"
},
"ns" : "mapa-servicos.estabelecimentos",
"name" : "localizacao.coordenadas_2dsphere"
}
]
Geospatial index
> lng = -46.80208830000004
> lat = -23.515985699999998
> distance = 30 / 6378.137
>
> db.estabelecimentos.find({ "localizacao.coordenadas" : { "$nearSphere" : [lng , lat] ,
"$maxDistance" : distance}}).limit(50)

http://mapa-servicos-publicos.herokuapp.com/
Aggregation Framework
Aggregation Framework

Pipeline Operators: $project, $match, $limit, $skip, $unwind, $group, $sort, $geoNear
Aggregation Framework
> db.estabelecimentos.aggregate([{$match : {'localizacao.uf' : 'SP'}}, {$group : {_id :
'$localizacao.cidade', qtd : {$sum : 1}}}, {$sort : {qtd : -1}}, {$limit : 3}])
{
"result" : [
{
"_id" : "SAO PAULO",
"qtd" : 6930
},
{
"_id" : "CAMPINAS",
"qtd" : 881
},
{
"_id" : "GUARULHOS",
"qtd" : 666
}
],
"ok" : 1
}
>
Mongo Driver for Java
Spring Data MongoDB
http://projects.spring.io/spring-data-mongodb/
Replica Sets
Replica Sets
• A replica set is a group of mongod instances that host the
same data set
• Replication provides redundancy and increases data
availability
• The primary accepts all write operations from clients (only
one primary allowed)
• Replication can be used to increase read capacity
• Asynchronous replication
• Automatic failover
Replica Sets
Replica Sets
Sharding
Sharding
Issues of scaling:
• High query rates can exhaust the CPU capacity of the server
• Larger data sets exceed the storage capacity of a single

machine
• Working set sizes larger than the system’s RAM stress the I/O
capacity of disk drives

Vertical scaling X Sharding
Sharding

Horizontally Scalable

• Sharding is the process of storing data across multiple machines
• Each shard is an independent database, and collectively, the shards make up a
single logical database
Sharded clusters
Range Based Sharding

• Supports more efficient range queries
• Results in an uneven distribution of data
• Monotonically increasing keys should be avoided
Hash Based Sharding

Ensures an even distribution of data at the expense of efficient range queries
https://education.mongodb.com/
Books
db.audience.find({‘question’ : true})
Thanks everyone!
Hope you’ve enjoyed it.

More Related Content

What's hot (20)

PDF
Embedding a language into string interpolator
Michael Limansky
 
PDF
MySQL flexible schema and JSON for Internet of Things
Alexander Rubin
 
PDF
MongoDBで作るソーシャルデータ新解析基盤
Takahiro Inoue
 
PDF
MongoDB With Style
Gabriele Lana
 
PPTX
Agg framework selectgroup feb2015 v2
MongoDB
 
PPTX
Webinar: Exploring the Aggregation Framework
MongoDB
 
PPT
jQuery Datatables With MongDb
sliimohara
 
KEY
Mongo db presentation
Julie Sommerville
 
PDF
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB
 
PDF
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
MongoDB
 
PDF
De normalised london aggregation framework overview
Chris Harris
 
PDF
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
MongoDB
 
PPTX
Operational Intelligence with MongoDB Webinar
MongoDB
 
KEY
MongoDB Aggregation Framework
Tyler Brock
 
PDF
MongoDB dla administratora
3camp
 
KEY
Geospatial Indexing and Querying with MongoDB
Grant Goodale
 
PPTX
MongoDB Aggregation
Amit Ghosh
 
PDF
MongoDB Aggregation Framework
Caserta
 
PPTX
The Aggregation Framework
MongoDB
 
PDF
Mobile Web 5.0
Michael Galpin
 
Embedding a language into string interpolator
Michael Limansky
 
MySQL flexible schema and JSON for Internet of Things
Alexander Rubin
 
MongoDBで作るソーシャルデータ新解析基盤
Takahiro Inoue
 
MongoDB With Style
Gabriele Lana
 
Agg framework selectgroup feb2015 v2
MongoDB
 
Webinar: Exploring the Aggregation Framework
MongoDB
 
jQuery Datatables With MongDb
sliimohara
 
Mongo db presentation
Julie Sommerville
 
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB
 
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
MongoDB
 
De normalised london aggregation framework overview
Chris Harris
 
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
MongoDB
 
Operational Intelligence with MongoDB Webinar
MongoDB
 
MongoDB Aggregation Framework
Tyler Brock
 
MongoDB dla administratora
3camp
 
Geospatial Indexing and Querying with MongoDB
Grant Goodale
 
MongoDB Aggregation
Amit Ghosh
 
MongoDB Aggregation Framework
Caserta
 
The Aggregation Framework
MongoDB
 
Mobile Web 5.0
Michael Galpin
 

Viewers also liked (20)

PPTX
Introduction to docker
removed_b0e2342824f6227286f54ba461ebc0fe
 
PPTX
Docker SF Meetup January 2016
Patrick Chanezon
 
PPTX
DockerCon EU 2015: Compute as an Interruption Forget the Servers
Docker, Inc.
 
PPTX
Docker Platform and Ecosystem Nov 2015
Patrick Chanezon
 
PDF
DockerCon EU 2015: Monitoring Docker
Docker, Inc.
 
PDF
10 Tips for WeChat
Chris Baker
 
PDF
20 Ideas for your Website Homepage Content
Barry Feldman
 
PPTX
study Seam Carving For Content Aware Image Resizing
Chiamin Hsu
 
PPTX
#Beyondgender workshops
Son Vivienne
 
PPT
Seeking Support in Secret
Son Vivienne
 
PPTX
Tech 7/8 Industries in newfoundland
lauodriscoll
 
DOCX
Etbis publish
nobitaemon
 
DOCX
k-12
Montia Dacelo
 
PDF
白石島提案書 Ver 2
Takahiko Nishimura
 
PPT
Y generacija
Robert Kamerer
 
PPT
Curating Networked Presence: Beyond Pseudonymity
Son Vivienne
 
PDF
Maria Jose Jorda UBS
Maria Jose Jorda Garcia
 
PPS
English Model Plan
Oziléa Couto
 
PPTX
Google sketchup
alej12
 
PPT
Lecture 2 registration of estate agents
Mohamad Isa Abdullah
 
Docker SF Meetup January 2016
Patrick Chanezon
 
DockerCon EU 2015: Compute as an Interruption Forget the Servers
Docker, Inc.
 
Docker Platform and Ecosystem Nov 2015
Patrick Chanezon
 
DockerCon EU 2015: Monitoring Docker
Docker, Inc.
 
10 Tips for WeChat
Chris Baker
 
20 Ideas for your Website Homepage Content
Barry Feldman
 
study Seam Carving For Content Aware Image Resizing
Chiamin Hsu
 
#Beyondgender workshops
Son Vivienne
 
Seeking Support in Secret
Son Vivienne
 
Tech 7/8 Industries in newfoundland
lauodriscoll
 
Etbis publish
nobitaemon
 
白石島提案書 Ver 2
Takahiko Nishimura
 
Y generacija
Robert Kamerer
 
Curating Networked Presence: Beyond Pseudonymity
Son Vivienne
 
Maria Jose Jorda UBS
Maria Jose Jorda Garcia
 
English Model Plan
Oziléa Couto
 
Google sketchup
alej12
 
Lecture 2 registration of estate agents
Mohamad Isa Abdullah
 
Ad

Similar to Talk MongoDB - Amil (20)

ODP
MongoDB - A Document NoSQL Database
Ruben Inoto Soto
 
PPTX
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB
 
PPTX
MongoDb and NoSQL
TO THE NEW | Technology
 
PPTX
Intro To Mongo Db
chriskite
 
PPTX
MongoDB_ppt.pptx
1AP18CS037ShirishKul
 
PDF
MongoDB FabLab León
Juan Antonio Roy Couto
 
PPTX
Einführung in MongoDB
NETUserGroupBern
 
PDF
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
NETWAYS
 
PDF
MongoDB.pdf
KuldeepKumar778733
 
KEY
Seedhack MongoDB 2011
Rainforest QA
 
KEY
Mongodb intro
christkv
 
PPTX
Geoindexing with MongoDB
leafnode
 
PDF
MongoDB Atlas Workshop - Singapore
Ashnikbiz
 
PDF
MongoDB
techwhizbang
 
PPT
Introduction to MongoDB
Ravi Teja
 
PPTX
Introduction to MongoDB – A NoSQL Database
manikgupta2k04
 
PPT
9. Document Oriented Databases
Fabio Fumarola
 
PDF
Using MongoDB and Python
Mike Bright
 
PDF
2016 feb-23 pyugre-py_mongo
Michael Bright
 
PDF
MongoDB Meetup
Maxime Beugnet
 
MongoDB - A Document NoSQL Database
Ruben Inoto Soto
 
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB
 
MongoDb and NoSQL
TO THE NEW | Technology
 
Intro To Mongo Db
chriskite
 
MongoDB_ppt.pptx
1AP18CS037ShirishKul
 
MongoDB FabLab León
Juan Antonio Roy Couto
 
Einführung in MongoDB
NETUserGroupBern
 
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
NETWAYS
 
MongoDB.pdf
KuldeepKumar778733
 
Seedhack MongoDB 2011
Rainforest QA
 
Mongodb intro
christkv
 
Geoindexing with MongoDB
leafnode
 
MongoDB Atlas Workshop - Singapore
Ashnikbiz
 
MongoDB
techwhizbang
 
Introduction to MongoDB
Ravi Teja
 
Introduction to MongoDB – A NoSQL Database
manikgupta2k04
 
9. Document Oriented Databases
Fabio Fumarola
 
Using MongoDB and Python
Mike Bright
 
2016 feb-23 pyugre-py_mongo
Michael Bright
 
MongoDB Meetup
Maxime Beugnet
 
Ad

Recently uploaded (20)

PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 

Talk MongoDB - Amil