Mongo DB
Click here to load reader
-
Upload
minsk-linux-user-group -
Category
Technology
-
view
148 -
download
0
description
Transcript of Mongo DB
![Page 1: Mongo DB](https://reader038.fdocuments.in/reader038/viewer/2022100500/55515bcfb4c9059f768b4b36/html5/thumbnails/1.jpg)
Hello
![Page 2: Mongo DB](https://reader038.fdocuments.in/reader038/viewer/2022100500/55515bcfb4c9059f768b4b36/html5/thumbnails/2.jpg)
MongoDB
• open-source• document-oriented• json/bson
![Page 3: Mongo DB](https://reader038.fdocuments.in/reader038/viewer/2022100500/55515bcfb4c9059f768b4b36/html5/thumbnails/3.jpg)
JSON
> db.users.findOne(){
"_id" : ObjectId("5099803df3f4948bd2f98391"),"name" : {
"first" : "Alan","last" : "Turing"
},"birth" : ISODate("1912-06-22T21:00:00Z"),"death" : ISODate("1954-06-06T21:00:00Z"),"views" : NumberLong(1250000)
}
![Page 4: Mongo DB](https://reader038.fdocuments.in/reader038/viewer/2022100500/55515bcfb4c9059f768b4b36/html5/thumbnails/4.jpg)
_id field
> db.users.findOne({}, {_id: 1, name: 1}){
"_id" : ObjectId("5099803df3f4948bd2f98391"),"name" : {
"first" : "Alan","last" : "Turing"
}}
> ObjectId("509..91").getTimestamp()ISODate("2012-11-06T21:25:17Z")
![Page 5: Mongo DB](https://reader038.fdocuments.in/reader038/viewer/2022100500/55515bcfb4c9059f768b4b36/html5/thumbnails/5.jpg)
BSON
• http://bsonspec.org/#/specification• http://groups.google.com/group/bson
![Page 6: Mongo DB](https://reader038.fdocuments.in/reader038/viewer/2022100500/55515bcfb4c9059f768b4b36/html5/thumbnails/6.jpg)
Schemaless
> db.users.update({_id: ObjectId("509..91")},{ $set: { born: "London, England" }})
> db.users.find({"name.first": "Alan"}){
"_id" : ObjectId("5099803df3f4948bd2f98391"),"birth" : ISODate("1912-06-22T21:00:00Z"),"born" : "London, England","death" : ISODate("1954-06-06T21:00:00Z"),"name" : {
"first" : "Alan","last" : "Turing"
},"views" : NumberLong(1250000)
}
![Page 7: Mongo DB](https://reader038.fdocuments.in/reader038/viewer/2022100500/55515bcfb4c9059f768b4b36/html5/thumbnails/7.jpg)
Storage
• mmap• OS page cache
![Page 8: Mongo DB](https://reader038.fdocuments.in/reader038/viewer/2022100500/55515bcfb4c9059f768b4b36/html5/thumbnails/8.jpg)
Journal
• present• group commit every 100ms, by default (2..300ms)
![Page 9: Mongo DB](https://reader038.fdocuments.in/reader038/viewer/2022100500/55515bcfb4c9059f768b4b36/html5/thumbnails/9.jpg)
Fault-tolerance
PRIMARY> rs.conf(){
"_id" : "rs2","version" : 3,"members" : [
{ "_id" : 0,"host" : "10.99.41.134:27017" },
{ "_id" : 1,"host" : "10.28.130.177:27017" },
{ "_id" : 2,"host" : "10.217.30.225:27017" } ]
}
![Page 10: Mongo DB](https://reader038.fdocuments.in/reader038/viewer/2022100500/55515bcfb4c9059f768b4b36/html5/thumbnails/10.jpg)
Sharding
• horizontal partitioning• multiple nodes• ‘config‘ servers, 1 or 3, sync. replication• ‘mongos‘ routers• db.runCommand(addshard: ... )• db.runCommand(removeshard: ... )• chunks, 64M, changeable• do it once, do it right• increasing monotonically• so do not shard by _id
![Page 11: Mongo DB](https://reader038.fdocuments.in/reader038/viewer/2022100500/55515bcfb4c9059f768b4b36/html5/thumbnails/11.jpg)
Locks, etc.
• server-wide lock, prior to 2.1• DB-level lock now• yield on page fault• ext3 fallocate, slow
![Page 12: Mongo DB](https://reader038.fdocuments.in/reader038/viewer/2022100500/55515bcfb4c9059f768b4b36/html5/thumbnails/12.jpg)
Coursera
“Functional Programming Principles in Scala” by Martin Odersky
https://class.coursera.org/progfun-002/class/index
![Page 13: Mongo DB](https://reader038.fdocuments.in/reader038/viewer/2022100500/55515bcfb4c9059f768b4b36/html5/thumbnails/13.jpg)