SlideShare una empresa de Scribd logo
1 de 47
MongoDB
My name is 
John Jenson
• 12 years writing code 
• 11 years using Oracle 
• 9 months using Mongo 
• BYU Alumnus 
• Principal Engineer @ Cengage 
• Currently doing MEAN stack dev
When to use 
MongoDB?
1.Don’t want/need a rigid schema 
1.Need horizontally scalable 
performance for high loads 
1.Make sure you won’t need real-time 
reporting that aggregates a 
lot of disparate data
Use Cases for Mongo
Photo Meta-Data 
Problem: 
•Business needed more flexibility than Oracle could deliver 
Solution: 
•Used MongoDB instead of Oracle 
RReessuullttss:: 
• Developed application in one sprint cycle 
• 500% cost reduction compared to Oracle 
• 900% performance improvement compared to Oracle 
• http://www.mongodb.com/customers/shutterfly 
Slide Courtesy of Steve Francia - http://spf13.com/presentation/mongodb-sort-conference-2011
Online Dictionary 
Problem: 
•MySQL could not scale to handle their 5B+ documents 
Solution: 
•Switched from MySQL to MongoDB 
Results: 
• Massive simplification of code base 
• Eliminated need for external caching system 
• 20x performance improvement over MySQL 
• http://www.mongodb.com/customers/reverb-technologies 
Slide Courtesy of Steve Francia - http://spf13.com/presentation/mongodb-sort-conference-2011
E-commerce 
Problem: 
•Multi-vertical E-commerce impossible to model (efficiently) in RDBMS 
Solution: 
•Switched from MySQL to MongoDB 
Results: 
• Massive simplification of code base 
• Rapidly build, halving time to market (and cost) 
• Eliminated need for external caching system 
• 50x+ improvement over MySQL 
Slide Courtesy of Steve Francia - http://spf13.com/presentation/mongodb-sort-conference-2011
Mongo’s Philosophy 
• Mongo tries to provide a good degree of 
functionality to handle a large set of use 
cases 
• sometimes need strong consistency / 
atomicity 
• secondary indexes 
• ad hoc queries
Had to leave out a few 
things in order to scale 
• No Joins 
• no choice here. Can’t have joins if we want to scale 
horizontally 
• No ACID Transactions 
• distributed transactions are hard to scale 
• Mongo does not support multi-document 
transactions 
• Only document level atomic operations provided
MongoDB 
• JSON Documents 
• Querying/Indexing/Updating similar to 
relational databases 
• Configurable Consistency 
• Auto-Sharding
Database Landscape 
Slide Courtesy of Steve Francia - http://spf13.com/presentation/mongodb-sort-conference-2011
MongoDB is: 
Horizontally Scalable 
Document 
Oriented 
{{ aauutthhoorr:: ““sstteevvee””,, 
ddaattee:: nneeww DDaattee(()),, 
tteexxtt:: ““AAbboouutt MMoonnggooDDBB......””,, 
ttaaggss:: [[““tteecchh””,, ““ddaattaabbaassee””]]}} 
Application 
High 
Performance 
Slide Courtesy of Steve Francia - http://spf13.com/presentation/mongodb-sort-conference-2011
“• MongoDB has the best 
features of key/ values stores, 
document databases and 
relational databases in one. 
• John Nunemaker
Schema Design
Normalized Relational Data 
Slide Courtesy of Steve Francia - http://spf13.com/presentation/mongodb-sort-conference-2011
Document databases make 
normalized data look like this 
Slide Courtesy of Steve Francia - http://spf13.com/presentation/mongodb-sort-conference-2011
Terminology 
RDBMS Mongo 
Table, View ➜ Collection 
Row ➜ JSON Document 
Index ➜ Index 
Join ➜ Embedded Document 
Partition ➜ Shard 
Partition Key ➜ Shard Key 
Slide Courtesy of Steve Francia - http://spf13.com/presentation/mongodb-sort-conference-2011
Create Collection 
> db.createCollection('posts’) 
SQL equivalent 
CREATE TABLE posts( 
col1 col1_type, 
col2 col2_type, 
…)
Insert Document 
> p = {author: "roger", 
date: new Date(), 
text: "about mongoDB...", 
tags: ["tech", "databases"]} 
> db.posts.save(p) 
SQL equivalent 
INSERT INTO posts (col1, col2, …) 
VALUES (val1, val2, …)
Querying 
> db.posts.find() 
> { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), 
author : "roger", 
date : "Sat Jul 24 2010 19:47:11", 
text : "About MongoDB...", 
tags : [ "tech", "databases" ] } 
SQL equivalent 
SELECT * FROM POSTS
Secondary Indexes 
• Create index on any field in document 
// 1 means ascending, -1 means descending 
> db.posts.ensureIndex({author: 1}) 
> db.posts.find({author: 'roger'}) 
> { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), 
author : "roger", 
... } 
SQL equivalent 
CREATE INDEX ON posts(author)
Conditional Query 
Operators 
– $all, $exists, $mod, $ne, $in, $nin, $nor, $or, 
$size, $type, $lt, $lte, $gt, $gte 
// find posts with any tags 
> db.posts.find( {tags: {$exists: true }} ) 
// find posts matching a regular expression 
> db.posts.find( {author: /^rog*/i } ) 
// count posts by author 
> db.posts.find( {author: ‘roger’} ).count()
Update Operations 
• $set, $unset, $inc, $push, $pushAll, 
$pull, $pullAll, $bit 
> comment = { author: “fred”, 
date: new Date(), 
text: “Best Movie Ever”} 
> db.posts.update( { _id: “...” }, 
$push: {comments: comment} );
Secondary Indexes 
// Index nested documents 
> db.posts.ensureIndex( “comments.author”: 1) 
> db.posts.find({‘comments.author’:’Fred’}) 
// Compound index 
> db.posts.ensureIndex({author: 1, date: 1}) 
> db.posts.find({author: ‘Fred’, date: { $gt: ‘Sat Apr 24 
2011 19:47:11’} }) 
// Multikey index (index on tags array) 
> db.posts.ensureIndex( tags: 1) 
> db.posts.find( { tags: ‘tech’ } ) 
// Text index 
> db.posts.ensureIndex( text: “text” ) 
> db.posts.find( { $text: { $search: ‘Mongo’} } )
Our Use Case for 
Mongo 
1.We needed to prototype some app 
ideas for a class test in the market. We 
didn’t want a hardened schema. Just 
wanted to get stuff out quick to try it out. 
2.We made sure that real-time analytic 
reporting wasn’t needed. 
3.We were using nodejs on the backend 
so Mongo was a natural fit.
What we gained by using Mongo 
• Faster turnaround in development 
• The flexibility to figure out our schema 
design as we went and change our minds 
often if needed 
• A database that we could scale 
horizontally if needed in the future
What we gave up by using Mongo 
• No multi-document transactions. This means 
We could not guarantee consistency in some 
cases. 
• Can’t write queries that use more than one 
collection. Aggregation framework only works 
on one collection at a time. Joining data has 
to be done programmatically and doesn’t 
scale. 
• Nesting isn’t always possible, and there are 
no foreign key constraints to enforce 
consistency.
Mongo Architecture
Limitations 
• Max BSON document size is 16MB 
– Mongo provides GridFS to get around this 
• No more than 100 levels of nesting 
• No more than 12 members in a replica set 
http://docs.mongodb.org/manual/reference/limits/
Scaling 
Sharding MongoDB
MongoDB Sharding 
• Shard data without no downtime 
• Automatic balancing as data is written 
• Range based or hash based sharding
Accessing a sharded 
collection 
• Inserts - must have the Shard Key 
• Updates - must have the Shard Key 
• Queries 
• With Shard Key - routed to nodes 
• Without Shard Key - scatter gather 
• Indexed Queries 
• With Shard Key - routed in order 
• Without Shard Key - distributed sort merge
High Availability
MongoDB Replication 
• MongoDB replication like MySQL replication 
(kinda) 
• Asynchronous master/slave 
• Variations 
•Master / slave 
•Replica Sets
Replication features 
• Reads from Primary are always consistent 
• Reads from Secondaries are eventually 
consistent 
• Automatic failover if a Primary fails 
• Automatic recovery when a node joins the set 
• Control of where writes occur
How MongoDB 
Replication works 
Member 1 
Member 2 
Member 3 
Set is made up of 2 or more nodes
How MongoDB 
Replication works 
Member 1 
Member 2 
PRIMARY 
Member 3 
Election establishes the PRIMARY 
Data replication from PRIMARY to SECONDARY
How MongoDB 
Replication works 
PRIMARY may fail 
Automatic election of new PRIMARY if majority 
exists 
Member 1 
Member 2 
DOWN 
Member 3 
negotiate 
new master
How MongoDB 
Replication works 
Member 1 
Member 2 
DOWN 
Member 3 
PRIMARY 
New PRIMARY elected 
Replication Set re-established
How MongoDB 
Replication works 
Member 1 
Member 3 
PRIMARY 
Member 2 
RECOVERING 
Automatic recovery
How MongoDB 
Replication works 
Member 1 
Member 3 
PRIMARY 
Member 2 
Replication Set re-established
Typical Deployments 
Use 
? 
Set 
size 
Data 
Protection 
High 
Availability Notes 
X One No No Must use --journal to protect against 
crashes 
Two Yes No On loss of one member, surviving member 
is read only 
Three Yes Yes - 1 failure On loss of one member, surviving two 
members can elect a new primary 
X Four Yes Yes - 1 failure* * On loss of two members, surviving two 
members are read only 
Five Yes Yes - 2 failures On loss of two members, surviving three 
members can elect a new primary
Replica Set features 
• A cluster of up to 12 servers 
• Any (one) node can be primary 
• Consensus election of primary 
• Automatic failover 
• Automatic recovery 
• All writes to primary 
• Reads can be to primary (default) or a 
secondary
Mongo Architecture
MongoDB Pros and Cons

Más contenido relacionado

La actualidad más candente

Introduction to mongo db
Introduction to mongo dbIntroduction to mongo db
Introduction to mongo dbRohit Bishnoi
 
3 scenarios when to use MongoDB!
3 scenarios when to use MongoDB!3 scenarios when to use MongoDB!
3 scenarios when to use MongoDB!Edureka!
 
Scaling with MongoDB
Scaling with MongoDBScaling with MongoDB
Scaling with MongoDBRick Copeland
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverMongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBJustin Smestad
 
When to Use MongoDB...and When You Should Not...
When to Use MongoDB...and When You Should Not...When to Use MongoDB...and When You Should Not...
When to Use MongoDB...and When You Should Not...MongoDB
 
Webinar: When to Use MongoDB
Webinar: When to Use MongoDBWebinar: When to Use MongoDB
Webinar: When to Use MongoDBMongoDB
 
MongoDB Administration ~ Kevin Hanson
MongoDB Administration ~ Kevin HansonMongoDB Administration ~ Kevin Hanson
MongoDB Administration ~ Kevin Hansonhungarianhc
 
Running MongoDB 3.0 on AWS
Running MongoDB 3.0 on AWSRunning MongoDB 3.0 on AWS
Running MongoDB 3.0 on AWSMongoDB
 
Agility and Scalability with MongoDB
Agility and Scalability with MongoDBAgility and Scalability with MongoDB
Agility and Scalability with MongoDBMongoDB
 
Non Relational Databases
Non Relational DatabasesNon Relational Databases
Non Relational DatabasesChris Baglieri
 
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...Prasoon Kumar
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBMike Dirolf
 

La actualidad más candente (20)

Introduction to mongo db
Introduction to mongo dbIntroduction to mongo db
Introduction to mongo db
 
3 scenarios when to use MongoDB!
3 scenarios when to use MongoDB!3 scenarios when to use MongoDB!
3 scenarios when to use MongoDB!
 
Scaling with MongoDB
Scaling with MongoDBScaling with MongoDB
Scaling with MongoDB
 
Mongo db intro.pptx
Mongo db intro.pptxMongo db intro.pptx
Mongo db intro.pptx
 
Mongo DB
Mongo DB Mongo DB
Mongo DB
 
Webinar: What's new in the .NET Driver
Webinar: What's new in the .NET DriverWebinar: What's new in the .NET Driver
Webinar: What's new in the .NET Driver
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
When to Use MongoDB...and When You Should Not...
When to Use MongoDB...and When You Should Not...When to Use MongoDB...and When You Should Not...
When to Use MongoDB...and When You Should Not...
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
 
Webinar: When to Use MongoDB
Webinar: When to Use MongoDBWebinar: When to Use MongoDB
Webinar: When to Use MongoDB
 
MongoDB Administration ~ Kevin Hanson
MongoDB Administration ~ Kevin HansonMongoDB Administration ~ Kevin Hanson
MongoDB Administration ~ Kevin Hanson
 
Running MongoDB 3.0 on AWS
Running MongoDB 3.0 on AWSRunning MongoDB 3.0 on AWS
Running MongoDB 3.0 on AWS
 
Agility and Scalability with MongoDB
Agility and Scalability with MongoDBAgility and Scalability with MongoDB
Agility and Scalability with MongoDB
 
Mongo db report
Mongo db reportMongo db report
Mongo db report
 
Non Relational Databases
Non Relational DatabasesNon Relational Databases
Non Relational Databases
 
No sq lv1_0
No sq lv1_0No sq lv1_0
No sq lv1_0
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
NoSQL benchmarking
NoSQL benchmarkingNoSQL benchmarking
NoSQL benchmarking
 

Similar a MongoDB Pros and Cons

Mongo db first steps with csharp
Mongo db first steps with csharpMongo db first steps with csharp
Mongo db first steps with csharpSerdar Buyuktemiz
 
The Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterThe Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterChris Henry
 
Mongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-finalMongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-finalMongoDB
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHPichikaway
 
Scaling with mongo db (with notes)
Scaling with mongo db (with notes)Scaling with mongo db (with notes)
Scaling with mongo db (with notes)emiltamas
 
MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Railsrfischer20
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB Habilelabs
 
MongoDB Introduction - Document Oriented Nosql Database
MongoDB Introduction - Document Oriented Nosql DatabaseMongoDB Introduction - Document Oriented Nosql Database
MongoDB Introduction - Document Oriented Nosql DatabaseSudhir Patil
 
MongoDB at Gilt Groupe
MongoDB at Gilt GroupeMongoDB at Gilt Groupe
MongoDB at Gilt GroupeMongoDB
 
Get More Out of MongoDB with TokuMX
Get More Out of MongoDB with TokuMXGet More Out of MongoDB with TokuMX
Get More Out of MongoDB with TokuMXTim Callaghan
 
10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCupWebGeek Philippines
 
MongoDB Knowledge Shareing
MongoDB Knowledge ShareingMongoDB Knowledge Shareing
MongoDB Knowledge ShareingPhilip Zhong
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDBNorberto Leite
 
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
 
Mongo db eveningschemadesign
Mongo db eveningschemadesignMongo db eveningschemadesign
Mongo db eveningschemadesignMongoDB APAC
 

Similar a MongoDB Pros and Cons (20)

MongoDB
MongoDBMongoDB
MongoDB
 
Mongo db first steps with csharp
Mongo db first steps with csharpMongo db first steps with csharp
Mongo db first steps with csharp
 
The Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb ClusterThe Care + Feeding of a Mongodb Cluster
The Care + Feeding of a Mongodb Cluster
 
Mongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-finalMongodb at-gilt-groupe-seattle-2012-09-14-final
Mongodb at-gilt-groupe-seattle-2012-09-14-final
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHP
 
Scaling with mongo db (with notes)
Scaling with mongo db (with notes)Scaling with mongo db (with notes)
Scaling with mongo db (with notes)
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Rails
 
Basics of MongoDB
Basics of MongoDB Basics of MongoDB
Basics of MongoDB
 
Mongo db
Mongo dbMongo db
Mongo db
 
mongodb tutorial
mongodb tutorialmongodb tutorial
mongodb tutorial
 
MongoDB Introduction - Document Oriented Nosql Database
MongoDB Introduction - Document Oriented Nosql DatabaseMongoDB Introduction - Document Oriented Nosql Database
MongoDB Introduction - Document Oriented Nosql Database
 
MongoDB at Gilt Groupe
MongoDB at Gilt GroupeMongoDB at Gilt Groupe
MongoDB at Gilt Groupe
 
Get More Out of MongoDB with TokuMX
Get More Out of MongoDB with TokuMXGet More Out of MongoDB with TokuMX
Get More Out of MongoDB with TokuMX
 
10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup10gen MongoDB Video Presentation at WebGeek DevCup
10gen MongoDB Video Presentation at WebGeek DevCup
 
MongoDB Knowledge Shareing
MongoDB Knowledge ShareingMongoDB Knowledge Shareing
MongoDB Knowledge Shareing
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
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
 
Mongo db eveningschemadesign
Mongo db eveningschemadesignMongo db eveningschemadesign
Mongo db eveningschemadesign
 
Mongodb
MongodbMongodb
Mongodb
 

Último

%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburgmasabamasaba
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 

Último (20)

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 

MongoDB Pros and Cons

  • 2. My name is John Jenson
  • 3. • 12 years writing code • 11 years using Oracle • 9 months using Mongo • BYU Alumnus • Principal Engineer @ Cengage • Currently doing MEAN stack dev
  • 4. When to use MongoDB?
  • 5. 1.Don’t want/need a rigid schema 1.Need horizontally scalable performance for high loads 1.Make sure you won’t need real-time reporting that aggregates a lot of disparate data
  • 7. Photo Meta-Data Problem: •Business needed more flexibility than Oracle could deliver Solution: •Used MongoDB instead of Oracle RReessuullttss:: • Developed application in one sprint cycle • 500% cost reduction compared to Oracle • 900% performance improvement compared to Oracle • http://www.mongodb.com/customers/shutterfly Slide Courtesy of Steve Francia - http://spf13.com/presentation/mongodb-sort-conference-2011
  • 8. Online Dictionary Problem: •MySQL could not scale to handle their 5B+ documents Solution: •Switched from MySQL to MongoDB Results: • Massive simplification of code base • Eliminated need for external caching system • 20x performance improvement over MySQL • http://www.mongodb.com/customers/reverb-technologies Slide Courtesy of Steve Francia - http://spf13.com/presentation/mongodb-sort-conference-2011
  • 9. E-commerce Problem: •Multi-vertical E-commerce impossible to model (efficiently) in RDBMS Solution: •Switched from MySQL to MongoDB Results: • Massive simplification of code base • Rapidly build, halving time to market (and cost) • Eliminated need for external caching system • 50x+ improvement over MySQL Slide Courtesy of Steve Francia - http://spf13.com/presentation/mongodb-sort-conference-2011
  • 10. Mongo’s Philosophy • Mongo tries to provide a good degree of functionality to handle a large set of use cases • sometimes need strong consistency / atomicity • secondary indexes • ad hoc queries
  • 11. Had to leave out a few things in order to scale • No Joins • no choice here. Can’t have joins if we want to scale horizontally • No ACID Transactions • distributed transactions are hard to scale • Mongo does not support multi-document transactions • Only document level atomic operations provided
  • 12. MongoDB • JSON Documents • Querying/Indexing/Updating similar to relational databases • Configurable Consistency • Auto-Sharding
  • 13. Database Landscape Slide Courtesy of Steve Francia - http://spf13.com/presentation/mongodb-sort-conference-2011
  • 14. MongoDB is: Horizontally Scalable Document Oriented {{ aauutthhoorr:: ““sstteevvee””,, ddaattee:: nneeww DDaattee(()),, tteexxtt:: ““AAbboouutt MMoonnggooDDBB......””,, ttaaggss:: [[““tteecchh””,, ““ddaattaabbaassee””]]}} Application High Performance Slide Courtesy of Steve Francia - http://spf13.com/presentation/mongodb-sort-conference-2011
  • 15. “• MongoDB has the best features of key/ values stores, document databases and relational databases in one. • John Nunemaker
  • 17. Normalized Relational Data Slide Courtesy of Steve Francia - http://spf13.com/presentation/mongodb-sort-conference-2011
  • 18. Document databases make normalized data look like this Slide Courtesy of Steve Francia - http://spf13.com/presentation/mongodb-sort-conference-2011
  • 19. Terminology RDBMS Mongo Table, View ➜ Collection Row ➜ JSON Document Index ➜ Index Join ➜ Embedded Document Partition ➜ Shard Partition Key ➜ Shard Key Slide Courtesy of Steve Francia - http://spf13.com/presentation/mongodb-sort-conference-2011
  • 20. Create Collection > db.createCollection('posts’) SQL equivalent CREATE TABLE posts( col1 col1_type, col2 col2_type, …)
  • 21. Insert Document > p = {author: "roger", date: new Date(), text: "about mongoDB...", tags: ["tech", "databases"]} > db.posts.save(p) SQL equivalent INSERT INTO posts (col1, col2, …) VALUES (val1, val2, …)
  • 22. Querying > db.posts.find() > { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "roger", date : "Sat Jul 24 2010 19:47:11", text : "About MongoDB...", tags : [ "tech", "databases" ] } SQL equivalent SELECT * FROM POSTS
  • 23. Secondary Indexes • Create index on any field in document // 1 means ascending, -1 means descending > db.posts.ensureIndex({author: 1}) > db.posts.find({author: 'roger'}) > { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), author : "roger", ... } SQL equivalent CREATE INDEX ON posts(author)
  • 24. Conditional Query Operators – $all, $exists, $mod, $ne, $in, $nin, $nor, $or, $size, $type, $lt, $lte, $gt, $gte // find posts with any tags > db.posts.find( {tags: {$exists: true }} ) // find posts matching a regular expression > db.posts.find( {author: /^rog*/i } ) // count posts by author > db.posts.find( {author: ‘roger’} ).count()
  • 25. Update Operations • $set, $unset, $inc, $push, $pushAll, $pull, $pullAll, $bit > comment = { author: “fred”, date: new Date(), text: “Best Movie Ever”} > db.posts.update( { _id: “...” }, $push: {comments: comment} );
  • 26. Secondary Indexes // Index nested documents > db.posts.ensureIndex( “comments.author”: 1) > db.posts.find({‘comments.author’:’Fred’}) // Compound index > db.posts.ensureIndex({author: 1, date: 1}) > db.posts.find({author: ‘Fred’, date: { $gt: ‘Sat Apr 24 2011 19:47:11’} }) // Multikey index (index on tags array) > db.posts.ensureIndex( tags: 1) > db.posts.find( { tags: ‘tech’ } ) // Text index > db.posts.ensureIndex( text: “text” ) > db.posts.find( { $text: { $search: ‘Mongo’} } )
  • 27. Our Use Case for Mongo 1.We needed to prototype some app ideas for a class test in the market. We didn’t want a hardened schema. Just wanted to get stuff out quick to try it out. 2.We made sure that real-time analytic reporting wasn’t needed. 3.We were using nodejs on the backend so Mongo was a natural fit.
  • 28. What we gained by using Mongo • Faster turnaround in development • The flexibility to figure out our schema design as we went and change our minds often if needed • A database that we could scale horizontally if needed in the future
  • 29. What we gave up by using Mongo • No multi-document transactions. This means We could not guarantee consistency in some cases. • Can’t write queries that use more than one collection. Aggregation framework only works on one collection at a time. Joining data has to be done programmatically and doesn’t scale. • Nesting isn’t always possible, and there are no foreign key constraints to enforce consistency.
  • 31. Limitations • Max BSON document size is 16MB – Mongo provides GridFS to get around this • No more than 100 levels of nesting • No more than 12 members in a replica set http://docs.mongodb.org/manual/reference/limits/
  • 33. MongoDB Sharding • Shard data without no downtime • Automatic balancing as data is written • Range based or hash based sharding
  • 34. Accessing a sharded collection • Inserts - must have the Shard Key • Updates - must have the Shard Key • Queries • With Shard Key - routed to nodes • Without Shard Key - scatter gather • Indexed Queries • With Shard Key - routed in order • Without Shard Key - distributed sort merge
  • 36. MongoDB Replication • MongoDB replication like MySQL replication (kinda) • Asynchronous master/slave • Variations •Master / slave •Replica Sets
  • 37. Replication features • Reads from Primary are always consistent • Reads from Secondaries are eventually consistent • Automatic failover if a Primary fails • Automatic recovery when a node joins the set • Control of where writes occur
  • 38. How MongoDB Replication works Member 1 Member 2 Member 3 Set is made up of 2 or more nodes
  • 39. How MongoDB Replication works Member 1 Member 2 PRIMARY Member 3 Election establishes the PRIMARY Data replication from PRIMARY to SECONDARY
  • 40. How MongoDB Replication works PRIMARY may fail Automatic election of new PRIMARY if majority exists Member 1 Member 2 DOWN Member 3 negotiate new master
  • 41. How MongoDB Replication works Member 1 Member 2 DOWN Member 3 PRIMARY New PRIMARY elected Replication Set re-established
  • 42. How MongoDB Replication works Member 1 Member 3 PRIMARY Member 2 RECOVERING Automatic recovery
  • 43. How MongoDB Replication works Member 1 Member 3 PRIMARY Member 2 Replication Set re-established
  • 44. Typical Deployments Use ? Set size Data Protection High Availability Notes X One No No Must use --journal to protect against crashes Two Yes No On loss of one member, surviving member is read only Three Yes Yes - 1 failure On loss of one member, surviving two members can elect a new primary X Four Yes Yes - 1 failure* * On loss of two members, surviving two members are read only Five Yes Yes - 2 failures On loss of two members, surviving three members can elect a new primary
  • 45. Replica Set features • A cluster of up to 12 servers • Any (one) node can be primary • Consensus election of primary • Automatic failover • Automatic recovery • All writes to primary • Reads can be to primary (default) or a secondary