Mongo presentation conf

351 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
351
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Mongo presentation conf

  1. 1. MongoDBIntroduction and InternalbyShridhar Joshi
  2. 2. What is MongoDB?Open source, scalable, high-performance, document-oriented NoSQL Key-Valueased database.Features•JSON-style document –oriented storage with schema-less•B-tree index supported on any attribute•Log-based replication for Master/Slave and Replica Set•Auto-sharding architecture (via horizontal partition) scales to thousands of no•NoSQL-style query•Surprising updating behaviors•Map/Reduce support•GridFS specification for storing large files•Developed by 10gen with commercial support
  3. 3. Well/Less Well SuitedSource: http://www.mongodb.org/display/DOCS/Use+Cases
  4. 4. Basic concepts in MongoDBNoSQL MongoDBDatabaseCollectionDocumentFieldIndexCursorRelational DBMSDatabaseRelationTupleColumnIndexCursorMongoDBDatabases*Collections*Documents* Indexes*Fields** means 0 or more objectsRelational DBMSDatabases*Relations*Columns* Indexes*Each document has its own fieldsand makes MongoDB schema-less.
  5. 5. CRUD Demo timeØshow dbs view existing databasesØuse test use database “test”Ødb.t.insert({name:’bob’,age:’30’}) insert 30 years bobØdb. t.insert({name:’alice’,gender:’female’}) insert lady aliceØdb. t.find() list all documents incollection tØdb. t.find({name:’bob’},{age:1}) find 1 year old bobØdb. t.find().limit(1).skip(1) find the second documentØdb. t.find().sort({name:1}) sort the results with ascendnameØdb. t.find({$or:[{name:’bob’},{name:’tom’}]}) find bob or tom’s documentsØdb. t.update({name:’ bob’},{$set:{age:31}}, update all bob’s age to 31Øfalse,true})Ødb.stats() database statisticØdb.getCollectionNames() collections under this dbØdb.t.ensureIndex({name:1}) create index on nameØdb.people.find({name:“bob"}).explain() explain plan step
  6. 6. Query Optimizationdb.people.find({x:10,y:”foo”})Index on xIndex on yCollection peopleIndex ScanIndex ScanDiskLocation Scan
  7. 7. MongoDB ArchitectureSource: mongoDB Replication and Replica Set by Dwight Merriman 10gen
  8. 8. MongoDB ShardingongoDB uses two key operations to facilitate sharding - split and migrate.plit splits a chunk into two ranges; it is done to assure no one chunk is unusually laigrate moves a chunk (the data associated with a key range) to another shard.his is done as needed to rebalance.plit is an inexpensive metadata operation, while migrate is expensive as large amodata may be moving server to server.oth splits and migrates are performed automatically.ongoDB has a sub-system called Balancer, which monitors shards loads and movehunks around if it finds an imbalance.you add a new shard to the system, some chunks will eventually be moved toat shard to spread out the load.recently split chunk may be moved immediately to a new shard if the systemedicts that future insertions will benefit from that move.
  9. 9. MongoDBShardingPull mode
  10. 10. MongoDB Sharding: BrieflyFROM:C TO:N#Copy Index Definition from C#Remove existing data in [min~max]#Clone the data in[min~max] from C#Ask C to replicate the changes#Make sure my view is complete and lock#Get the document’s DiskLoc for sharding#Trigger the N to sharding in Pull modeSequence#N commit#Ask N to commit
  11. 11. MongoDB Sharding: In DetailsFROM TONotice: The FROM can be updated/deleted during sharding and TO can catch up instep 4.
  12. 12. Replication and ShardingSource:
  13. 13. MongoDB Replication: Pull modeSlave continuously pull the OpLog from Master.
  14. 14. QuestionReference:1: Source code digest: http://www.cnblogs.com/daizhj/category/260889.html2: Books http://www.mongodb.org/display/DOCS/Books3: MongoDB offical website http://www.mongodb.com/

×