SlideShare a Scribd company logo
An introduction to MongoDB
Rácz Gábor
ELTE IK, 2013. febr. 10.
2
NoSQL
• Key-value
• Graph database
• Document-oriented
• Column family
3
Document store
RDBMS MongoDB
Database Database
Table, View Collection
Row Document (JSON, BSON)
Column Field
Index Index
Join Embedded Document
Foreign Key Reference
Partition Shard
4
Document store
RDBMS MongoDB
Database Database
Table, View Collection
Row Document (JSON, BSON)
Column Field
Index Index
Join Embedded Document
Foreign Key Reference
Partition Shard
> db.user.findOne({age:39})
{
"_id" : ObjectId("5114e0bd42…"),
"first" : "John",
"last" : "Doe",
"age" : 39,
"interests" : [
"Reading",
"Mountain Biking ]
"favorites": {
"color": "Blue",
"sport": "Soccer"}
}
5
CRUD
• Create
• db.collection.insert( <document> )
• db.collection.save( <document> )
• db.collection.update( <query>, <update>, { upsert: true } )
• Read
• db.collection.find( <query>, <projection> )
• db.collection.findOne( <query>, <projection> )
• Update
• db.collection.update( <query>, <update>, <options> )
• Delete
• db.collection.remove( <query>, <justOne> )
6
CRUD example
> db.user.insert({
first: "John",
last : "Doe",
age: 39
})
> db.user.find ()
{
"_id" : ObjectId("51…"),
"first" : "John",
"last" : "Doe",
"age" : 39
}
> db.user.update(
{"_id" : ObjectId("51…")},
{
$set: {
age: 40,
salary: 7000}
}
)
> db.user.remove({
"first": /^J/
})
7
Features
• Document-Oriented
storege
• Full Index Support
• Replication & High
Availability
• Auto-Sharding
• Querying
• Fast In-Place Updates
• Map/Reduce
Agile
Scalable
8
Memory Mapped Files
• „A memory-mapped file is a segment of virtual memory which
has been assigned a direct byte-for-byte correlation with
some portion of a file or file-like resource.”1
• mmap()
1: http://en.wikipedia.org/wiki/Memory-mapped_file
9
Replica Sets
• Redundancy and Failover
• Zero downtime for
upgrades and maintaince
• Master-slave replication
• Strong Consistency
• Delayed Consistency
• Geospatial features
Host1:10000
Host2:10001
Host3:10002
replica1
Client
10
Sharding
• Partition your data
• Scale write
throughput
• Increase capacity
• Auto-balancing
Host1:10000 Host2:10010
Host3:20000
shard1 shard2
Host4:30000
configdb
Client
11
Mixed
Host4:10010
Host5:20000
shard1
shardn
Host6:30000
configdb
Client
Host1:10000
Host2:10001
Host3:10002
replica1
Host7:30000
...
12
Map/Reduce
db.collection.mapReduce(
<mapfunction>,
<reducefunction>,
{
out: <collection>,
query: <>,
sort: <>,
limit: <number>,
finalize: <function>,
scope: <>,
jsMode: <boolean>,
verbose: <boolean>
}
)
var mapFunction1 = function() { emit(this.cust_id, this.price); };
var reduceFunction1 = function(keyCustId, valuesPrices)
{ return sum(valuesPrices); };
13
Other features
• Easy to install and use
• Detailed documentation
• Various APIs
• JavaScript, Python, Ruby, Perl, Java, Java, Scala, C#, C++, Haskell,
Erlang
• Community
• Open source
14
Theory of noSQL: CAP
CAP Theorem:
satisfying all three at the
same time is impossible
A P
• Many nodes
• Nodes contain replicas of
partitions of data
• Consistency
• all replicas contain the same
version of data
• Availability
• system remains operational on
failing nodes
• Partition tolarence
• multiple entry points
• system remains operational on
system split
C
15
Theory of noSQL: CAP
CAP Theorem:
satisfying all three at the
same time is impossible
A P
• Many nodes
• Nodes contain replicas of
partitions of data
• Consistency
• all replicas contain the same
version of data
• Availability
• system remains operational on
failing nodes
• Partition tolarence
• multiple entry points
• system remains operational on
system split
C
16
ACID - BASE
Pritchett, D.: BASE: An Acid Alternative (queue.acm.org/detail.cfm?id=1394128)
•Atomicity
•Consistency
•Isolation
•Durability
•Basically
Available (CP)
•Soft-state
•Eventually
consistent (AP)
17
THANK YOU

More Related Content

PPT
PPT
lecture_40_1.ppt
PPT
MongoDB Basics Introduction along with MapReduce
PPT
MongoDB a été développé par la société basée à New York 10gen en 2007, dans l...
PPT
Lecture 40 1
PPT
Mongodb
PPTX
mongoyeieheheieueheheueuehwwuwuuuwuwh.pptx
PPTX
Introduction to MongoDB and Workshop
lecture_40_1.ppt
MongoDB Basics Introduction along with MapReduce
MongoDB a été développé par la société basée à New York 10gen en 2007, dans l...
Lecture 40 1
Mongodb
mongoyeieheheieueheheueuehwwuwuuuwuwh.pptx
Introduction to MongoDB and Workshop

Similar to lecture_40_1.pptx (20)

ODP
MongoDB - A Document NoSQL Database
PDF
MongoDB.pdf
PDF
An Introduction to MongoDB
PPTX
MongoDB_ppt.pptx
KEY
PPTX
MongoDB 3.0
PPT
Building Your First MongoDB App ~ Metadata Catalog
PPT
9. Document Oriented Databases
PDF
MongoDB Atlas Workshop - Singapore
PPTX
lecture_34e.pptx
PPTX
introduction to Mongodb
PPTX
MongoDB by Emroz sardar.
PDF
Quick overview on mongo db
KEY
Mongodb intro
PDF
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
PDF
20-NoSQLMongoDbiig data analytics hB.pdf
PDF
Baisc introduction of mongodb for beginn
PPTX
An Introduction To NoSQL & MongoDB
PPTX
MongoDB 2.4 and spring data
PDF
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB - A Document NoSQL Database
MongoDB.pdf
An Introduction to MongoDB
MongoDB_ppt.pptx
MongoDB 3.0
Building Your First MongoDB App ~ Metadata Catalog
9. Document Oriented Databases
MongoDB Atlas Workshop - Singapore
lecture_34e.pptx
introduction to Mongodb
MongoDB by Emroz sardar.
Quick overview on mongo db
Mongodb intro
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
20-NoSQLMongoDbiig data analytics hB.pdf
Baisc introduction of mongodb for beginn
An Introduction To NoSQL & MongoDB
MongoDB 2.4 and spring data
MongoDB for Coder Training (Coding Serbia 2013)

Recently uploaded (20)

PPTX
climate analysis of Dhaka ,Banglades.pptx
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PPTX
Business Ppt On Nestle.pptx huunnnhhgfvu
PPTX
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PPTX
Introduction-to-Cloud-ComputingFinal.pptx
PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
PPTX
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
PPT
Miokarditis (Inflamasi pada Otot Jantung)
PPT
Quality review (1)_presentation of this 21
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
PPTX
1_Introduction to advance data techniques.pptx
PPTX
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
PPTX
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
PPTX
Supervised vs unsupervised machine learning algorithms
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PDF
Clinical guidelines as a resource for EBP(1).pdf
PDF
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
PPTX
Introduction to Knowledge Engineering Part 1
PDF
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
climate analysis of Dhaka ,Banglades.pptx
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
Business Ppt On Nestle.pptx huunnnhhgfvu
Introduction to Basics of Ethical Hacking and Penetration Testing -Unit No. 1...
IBA_Chapter_11_Slides_Final_Accessible.pptx
Introduction-to-Cloud-ComputingFinal.pptx
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
The THESIS FINAL-DEFENSE-PRESENTATION.pptx
Miokarditis (Inflamasi pada Otot Jantung)
Quality review (1)_presentation of this 21
STUDY DESIGN details- Lt Col Maksud (21).pptx
1_Introduction to advance data techniques.pptx
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
Supervised vs unsupervised machine learning algorithms
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
Clinical guidelines as a resource for EBP(1).pdf
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
Introduction to Knowledge Engineering Part 1
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”

lecture_40_1.pptx

  • 1. An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10.
  • 2. 2 NoSQL • Key-value • Graph database • Document-oriented • Column family
  • 3. 3 Document store RDBMS MongoDB Database Database Table, View Collection Row Document (JSON, BSON) Column Field Index Index Join Embedded Document Foreign Key Reference Partition Shard
  • 4. 4 Document store RDBMS MongoDB Database Database Table, View Collection Row Document (JSON, BSON) Column Field Index Index Join Embedded Document Foreign Key Reference Partition Shard > db.user.findOne({age:39}) { "_id" : ObjectId("5114e0bd42…"), "first" : "John", "last" : "Doe", "age" : 39, "interests" : [ "Reading", "Mountain Biking ] "favorites": { "color": "Blue", "sport": "Soccer"} }
  • 5. 5 CRUD • Create • db.collection.insert( <document> ) • db.collection.save( <document> ) • db.collection.update( <query>, <update>, { upsert: true } ) • Read • db.collection.find( <query>, <projection> ) • db.collection.findOne( <query>, <projection> ) • Update • db.collection.update( <query>, <update>, <options> ) • Delete • db.collection.remove( <query>, <justOne> )
  • 6. 6 CRUD example > db.user.insert({ first: "John", last : "Doe", age: 39 }) > db.user.find () { "_id" : ObjectId("51…"), "first" : "John", "last" : "Doe", "age" : 39 } > db.user.update( {"_id" : ObjectId("51…")}, { $set: { age: 40, salary: 7000} } ) > db.user.remove({ "first": /^J/ })
  • 7. 7 Features • Document-Oriented storege • Full Index Support • Replication & High Availability • Auto-Sharding • Querying • Fast In-Place Updates • Map/Reduce Agile Scalable
  • 8. 8 Memory Mapped Files • „A memory-mapped file is a segment of virtual memory which has been assigned a direct byte-for-byte correlation with some portion of a file or file-like resource.”1 • mmap() 1: http://en.wikipedia.org/wiki/Memory-mapped_file
  • 9. 9 Replica Sets • Redundancy and Failover • Zero downtime for upgrades and maintaince • Master-slave replication • Strong Consistency • Delayed Consistency • Geospatial features Host1:10000 Host2:10001 Host3:10002 replica1 Client
  • 10. 10 Sharding • Partition your data • Scale write throughput • Increase capacity • Auto-balancing Host1:10000 Host2:10010 Host3:20000 shard1 shard2 Host4:30000 configdb Client
  • 12. 12 Map/Reduce db.collection.mapReduce( <mapfunction>, <reducefunction>, { out: <collection>, query: <>, sort: <>, limit: <number>, finalize: <function>, scope: <>, jsMode: <boolean>, verbose: <boolean> } ) var mapFunction1 = function() { emit(this.cust_id, this.price); }; var reduceFunction1 = function(keyCustId, valuesPrices) { return sum(valuesPrices); };
  • 13. 13 Other features • Easy to install and use • Detailed documentation • Various APIs • JavaScript, Python, Ruby, Perl, Java, Java, Scala, C#, C++, Haskell, Erlang • Community • Open source
  • 14. 14 Theory of noSQL: CAP CAP Theorem: satisfying all three at the same time is impossible A P • Many nodes • Nodes contain replicas of partitions of data • Consistency • all replicas contain the same version of data • Availability • system remains operational on failing nodes • Partition tolarence • multiple entry points • system remains operational on system split C
  • 15. 15 Theory of noSQL: CAP CAP Theorem: satisfying all three at the same time is impossible A P • Many nodes • Nodes contain replicas of partitions of data • Consistency • all replicas contain the same version of data • Availability • system remains operational on failing nodes • Partition tolarence • multiple entry points • system remains operational on system split C
  • 16. 16 ACID - BASE Pritchett, D.: BASE: An Acid Alternative (queue.acm.org/detail.cfm?id=1394128) •Atomicity •Consistency •Isolation •Durability •Basically Available (CP) •Soft-state •Eventually consistent (AP)