[go: up one dir, main page]

0% found this document useful (0 votes)
1 views18 pages

Lecture 40 1

Uploaded by

Chellam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views18 pages

Lecture 40 1

Uploaded by

Chellam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

An introduction to MongoDB

Rácz Gábor

ELTE IK, 2013. febr. 10.


In Production

http://www.mongodb.org/about/production-deployments/
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 > db.user.findOne({age:39})
Table, View Collection {
Row "_id" : ObjectId("5114e0bd42…"),
Document (JSON, BSON)
"first" : "John",
Column Field
"last" : "Doe",
Index Index "age" : 39,
Join Embedded Document"interests" : [
Foreign Key Reference "Reading",
Partition Shard "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.find ()
> db.user.insert({ {
first: "John", "_id" : ObjectId("51…"),
last : "Doe", "first" : "John",
age: 39 "last" : "Doe",
}) "age" : 39
}

> db.user.update(
{"_id" : ObjectId("51…")},
{
> db.user.remove({
$set: {
"first": /^J/
age: 40,
salary: 7000} }) 7
}
)
Features
• Document-Oriented storege
• Full Index Support
• Replication & High Agile
Availability
• Auto-Sharding
• Querying
• Fast In-Place Updates Scalable
• Map/Reduce
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()

: http://en.wikipedia.org/wiki/Memory-mapped_file
1
Replica Sets Host1:10000

• Redundancy and Failover Host2:10001

• Zero downtime for Host3:10002


upgrades and maintaince replica1

• Master-slave replication
Client
• Strong Consistency
• Delayed Consistency

• Geospatial features
10
Sharding
• Partition your data
• Scale write
throughput
• Increase capacity
• Auto-balancing
shard1 shard2
Host1:10000 Host2:10010

configdb
Host3:20000
11
Host4:30000 Client
Mixed
shard1

...
Host1:10000
shardn
Host2:10001 Host4:10010

Host3:10002
replica1

configdb
Host5:20000

Host6:30000 Client

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); }; 13
var reduceFunction1 = function(keyCustId, valuesPrices)
{ return sum(valuesPrices); };
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
• Many nodes
C
• Nodes contain replicas of
partitions of data

• Consistency
• all replicas contain the same
version of data
• Availability
• system remains operational on
A P
failing nodes
• Partition tolarence CAP Theorem:
• multiple entry points satisfying all three at
• system remains operational on
system split
the same time is 15
impossible
Theory of noSQL: CAP
• Many nodes
C
• Nodes contain replicas of
partitions of data

• Consistency
• all replicas contain the same
version of data
• Availability
• system remains operational on
A P
failing nodes
• Partition tolarence CAP Theorem:
• multiple entry points satisfying all three at
• system remains operational on
system split
the same time is 16
impossible
ACID - BASE

•Basically
•Atomicity
Available (CP)
•Consistency •Soft-state
•Isolation •Eventually
•Durability
consistent (AP)

17

Pritchett, D.: BASE: An Acid Alternative (queue.acm.org/detail.cfm?id=1394128)


Thank you for your attention!

18

You might also like