MongoDB: Replication,Sharding,MapReduce

4,349 views
4,150 views

Published on

Published in: Technology, Education
0 Comments
9 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,349
On SlideShare
0
From Embeds
0
Number of Embeds
54
Actions
Shares
0
Downloads
96
Comments
0
Likes
9
Embeds 0
No embeds

No notes for slide

MongoDB: Replication,Sharding,MapReduce

  1. 1. { "_id" : ObjectId("4dcd3ebc9278000000005158"), "timestamp" : ISODate("2011-05-13T14:22:46.777Z"), "binary" : BinData(0,""), "string" : "abc", "number" : 3, "subobj" : {"subA": 1, "subB": 2 }, "array" : [1, 2, 3], "dbref" : [_id1, _id2, _id3] padding}
  2. 2. { db.coll.find({"string": "abc"});db.coll.find({ "string" : /^a.*$/i }); "_id" : ObjectId("4dcd3ebc9278000000005158"), "timestamp" : ISODate("2011-05-13T14:22:46.777Z"), db.coll.find({"subobj.subA": 1}); db.coll.find({"subobj.subB": {$exists: true} }); "binary" : BinData(0,""), "string" : "abc", db.coll.find({"number": 3}); db.coll.find({"number": {$gt: 1}}); "number" : 3, "subobj" : {"subA": 1, "subB": 2 }, "array" : [1, 2, 3], db.coll.find({"array": {$all:[1, 2]} }); "dbref" : [_id1, _id2, _id3] db.coll.find({"array": {$in:[2, 4, 6]} }); padding}
  3. 3. { "_id" : ObjectId("4dcd3ebc9278000000005158"), "timestamp" : ISODate("2011-05-13T14:22:46.777Z"), { $set : {"string": "def"} } "binary" : BinData(0,""), { $inc : {"number": 1} } "string" : "def", { $pull : {"subobj": {"subB": 2 } } } "number" : 4, "subobj" : {"subA": 1, "subB": 2 }, "array" : [1, 2, 3, 4, 5, 6], "dbref"$addToSet : { "array" : { $each : [ 4 , 5 , 6 ] } } } { : [_id1, _id2, _id3] "newkey" : "In-place"} { $set : {"newkey": "In-place"} }
  4. 4. Member1 Member2Primary SecondaryMember4 Member3Secondary Secondary
  5. 5. Member1 Member2Primary SecondaryMember4 Member3Secondary Secondary
  6. 6. Member1 Member2Primary SecondaryMember4 Member3Secondary Secondary
  7. 7. Member2 SecondaryMember4 Member3Secondary Secondary
  8. 8. Member1 PrimaryMember6 Member2Secondary SecondaryMember5 Member3Secondary Secondary Member4 Secondary
  9. 9. Member1 PrimaryMember6 Member2Secondary SecondaryMember5 Member3Secondary Secondary Member4 Secondary
  10. 10. Member1 PrimaryMember6 Member2Secondary SecondaryMember5 Member3Secondary Secondary Member4 Secondary
  11. 11. Chunk Shard Key Chunk 200MB
  12. 12. Cluster Shard Servers (Data) config Servers (Shard Configration) shard1 shard2 shard3 [ a, f ) [ k, n) [ o, t ) Chunk [ f, k ) [ n, o ) [ t, } ) mongos Servers (Routers)
  13. 13. http://www.mongodb.org/display/DOCS/Introduction
  14. 14. primary Shard primary 1 ( mongosprimary primary primary ) Shardcinfig Shard mongos http://www.mongodb.org/display/DOCS/Introduction
  15. 15. shard1 shard2[ a, f ) [ n, o ) [ o, t) [ 0, 9)[ f, k ) [ k, n) shard1 shard2[ a, f ) [ o, t) [ n, o )[ f, k ) [ k, n) [ 0, 9)
  16. 16. m = function(){ this.tags.forEach{ function(z) { emit(z, {count: 1}); } };};r = function(key, values) { var total=0; for (i=0, i<values.length, i++) total += values[i].count; return { count : total };}res=db.things.mapReduce(m,!r);# finalize

×