an introduction to mongodb rácz gábor elte ik, 2013. febr. 10
TRANSCRIPT
![Page 1: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/1.jpg)
An introduction to MongoDB
Rácz Gábor
ELTE IK, 2013. febr. 10.
![Page 2: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/2.jpg)
2
In Production
http://www.mongodb.org/about/production-deployments/
![Page 3: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/3.jpg)
3
NoSQL
• Key-value
• Graph database
• Document-oriented
• Column family
![Page 4: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/4.jpg)
4
Document storeRDBMS MongoDB
Database Database
Table, View Collection
Row Document (JSON, BSON)
Column Field
Index Index
Join Embedded Document
Foreign Key Reference
Partition Shard
![Page 5: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/5.jpg)
5
Document storeRDBMS 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"} }
![Page 6: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/6.jpg)
6
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> )
![Page 7: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/7.jpg)
7
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/
})
![Page 8: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/8.jpg)
8
Features• Document-Oriented storege• Full Index Support• Replication & High
Availability• Auto-Sharding• Querying• Fast In-Place Updates• Map/Reduce
Agile
Scalable
![Page 9: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/9.jpg)
9
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
![Page 10: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/10.jpg)
10
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
![Page 11: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/11.jpg)
11
Sharding• Partition your data• Scale write
throughput• Increase capacity
• Auto-balancing
Host1:10000 Host2:10010
Host3:20000
shard1 shard2
Host4:30000
configdb
Client
![Page 12: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/12.jpg)
12
Mixed
Host4:10010
Host5:20000
shard1
shardn
Host6:30000
configdb
Client
Host1:10000
Host2:10001
Host3:10002
replica1
Host7:30000
...
![Page 13: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/13.jpg)
13
Map/Reducedb.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); };
![Page 14: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/14.jpg)
14
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
![Page 15: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/15.jpg)
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
![Page 16: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/16.jpg)
16
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
![Page 17: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/17.jpg)
17
ACID - BASE
Pritchett, D.: BASE: An Acid Alternative (queue.acm.org/detail.cfm?id=1394128)
•Atomicity•Consistency•Isolation•Durability
•BasicallyAvailable (CP)•Soft-state•Eventually
consistent (AP)
![Page 18: An introduction to MongoDB Rácz Gábor ELTE IK, 2013. febr. 10](https://reader030.vdocuments.us/reader030/viewer/2022020111/56649db35503460f94aa3b77/html5/thumbnails/18.jpg)
18
Thank you for your attention!