Istanbul HackersGeekly WeeklyMongo DB@hserdarb
Why MongoDB?• Easy to use nosql• Good for web projects• Popular • High performance (No joins and embedding makes reads an...
What’s MongoDB good for?• Account and user profiles: can store arrays of addresses with ease• CMS: the flexible schema of ...
The Modern Need From Databases• Easy to use when project is small• Developing schema less• When we need scale it must be e...
RDBMS => MongoDBRDBMS MongoDBTable, View CollectionRow JSON DocumentIndex IndexJoin Embeded DocumentPartition ShardPartiti...
What is BSON?• MongoDB uses BSON as the data storage and network transfer formatfor "documents".• Short for Binary JSON• h...
Working with Entity Objects• Things can be really easy for you if you follow these rules for yourentities• Has a public no...
CRUDhttps://github.com/serdarb/IstanbulHackersCodeReviewSample/blob/master/AgileWall.Domain/Repo/BaseRepo.cs
Write Concern• Acknowledged• Write operations that use this write concern will wait for acknowledgement from the primaryse...
Journaling• Process starts with private view• Private view writes to journal• Journal updates shared view• Shared view upd...
Index• BasketItems.CreateIndex(“UserId”);
A tip for better indexing• Run mongodb with notablescan parameter and be sure your yourqueries are not making full table s...
Map Reduce
Transaction• MongoDB does not support transactions.• It is good to use relational databases (oracle, sql server) for thisp...
Sharding & ReplicationSharding is for scale out, replication is for high availability
Replication• Copies of your data for data safety• Asynchronous replication• Master - Slave model• Not master-master, when ...
Sharding (partitioning)• MongoDB does range basedpartitioning• Name begins with A, B-E, F-H ….• Shardkey is important!• Ba...
Sources• education.10gen.com• http://openmymind.net/mongodb.pdf• http://www.mongodb.org/display/DOCS/Introduction• http://...
Upcoming SlideShare
Loading in...5
×

MongoDB

618

Published on

a presentation made at istanbul hackers geekly weekly

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

No Downloads
Views
Total Views
618
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
22
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

MongoDB

  1. 1. Istanbul HackersGeekly WeeklyMongo DB@hserdarb
  2. 2. Why MongoDB?• Easy to use nosql• Good for web projects• Popular • High performance (No joins and embedding makes reads and writes fast)• High availability (Replicated servers with automatic master failover)• Easy scalability (Automatic sharding)
  3. 3. What’s MongoDB good for?• Account and user profiles: can store arrays of addresses with ease• CMS: the flexible schema of MongoDB is great for heterogeneous collections of content types• Form data: MongoDB makes it easy to evolve structure of form data over time• Blogs / user-generated content: can keep data with complex relationships together in one object• Messaging: vary message meta-data easily per message or message type without needing tomaintain separate collections or schemas• System configuration: just a nice object graph of configuration values, which is very natural inMongoDB• Log data of any kind: structured log data is the future• Graphs: just objects and pointers – a perfect fit• Location based data: MongoDB understands geo-spatial coordinates and natively supports geo-spatial indexinghttp://blog.mongolab.com/2012/08/why-is-mongodb-wildly-popular/
  4. 4. The Modern Need From Databases• Easy to use when project is small• Developing schema less• When we need scale it must be easy and cheap• No data loss• High Availability
  5. 5. RDBMS => MongoDBRDBMS MongoDBTable, View CollectionRow JSON DocumentIndex IndexJoin Embeded DocumentPartition ShardPartition Key Shard Key
  6. 6. What is BSON?• MongoDB uses BSON as the data storage and network transfer formatfor "documents".• Short for Binary JSON• http://bsonspec.org/• http://www.mongodb.org/display/DOCS/BSON
  7. 7. Working with Entity Objects• Things can be really easy for you if you follow these rules for yourentities• Has a public no-argument constructor• Has a public get set property for each value you want to have serialized
  8. 8. CRUDhttps://github.com/serdarb/IstanbulHackersCodeReviewSample/blob/master/AgileWall.Domain/Repo/BaseRepo.cs
  9. 9. Write Concern• Acknowledged• Write operations that use this write concern will wait for acknowledgement from the primaryserver before returning.• Unacknowledged• Write operations that use this write concern will return as soon as the message is written tothe socket.• Journaled• Exceptions are raised for network issues, and server errors; the write operation waits for theserver to group commit to the journal file on disk.• Replica Acknowledged• Exceptions are raised for network issues, and server errors; waits for at least 2 servers for thewrite operation.http://docs.mongodb.org/manual/core/write-concern/http://api.mongodb.org/java/current/com/mongodb/WriteConcern.htmlhttps://github.com/mongodb/mongo-csharp-driver/blob/master/MongoDB.Driver/WriteConcern.cs
  10. 10. Journaling• Process starts with private view• Private view writes to journal• Journal updates shared view• Shared view updates private view• Shared view flushes data to diskhttp://www.kchodorow.com/blog/2012/10/04/how-mongodbs-journaling-works/
  11. 11. Index• BasketItems.CreateIndex(“UserId”);
  12. 12. A tip for better indexing• Run mongodb with notablescan parameter and be sure your yourqueries are not making full table scans...• You get exceptions if a query needs a table scan, it gives you a chance to fixyour indexes on development time.
  13. 13. Map Reduce
  14. 14. Transaction• MongoDB does not support transactions.• It is good to use relational databases (oracle, sql server) for thispurpose• If you are stuck in a situation that needs transactions with MongoDByou must implement it by your self.• http://docs.mongodb.org/manual/tutorial/perform-two-phase-commits/• https://github.com/rystsov/mongodb-transaction-example
  15. 15. Sharding & ReplicationSharding is for scale out, replication is for high availability
  16. 16. Replication• Copies of your data for data safety• Asynchronous replication• Master - Slave model• Not master-master, when your data changethere are times that you only have one master…• Statement based• For example, insert statement send to thereplica and will run there…• Driver is replica set aware,• Connection to replica setmongodb://server1,server2:27017,server2:27018
  17. 17. Sharding (partitioning)• MongoDB does range basedpartitioning• Name begins with A, B-E, F-H ….• Shardkey is important!• Bad shard key choice can causetoo many split and mergeoperations on chunksmongodmongodmongodReplicasetmongodmongodmongodReplicasetS1 S2mongosmongodmongodmongodConfigServerClient1234
  18. 18. Sources• education.10gen.com• http://openmymind.net/mongodb.pdf• http://www.mongodb.org/display/DOCS/Introduction• http://www.mongodb.org/display/DOCS/Padding+Factor• https://github.com/mongodb/mongo• http://www.codeproject.com/Articles/273145/Using-MongoDB-with-the-Official-Csharp-Driver• http://stackoverflow.com/questions/4067197/mongodb-and-joins• http://www.mongodb.org/display/DOCS/Schema+Design#SchemaDesign-EmbeddingandLinking• http://docs.mongodb.org/manual/applications/database-references/• http://www.10gen.com/presentations?programming_lang=46• https://speakerdeck.com/mongodb/whats-new-in-the-net-driver• http://learnmongo.com/• http://www.mongovue.com/2010/11/03/yet-another-mongodb-map-reduce-tutorial/• http://spp42.com/mongodbde-dogru-index-kullanimi-nasil-kontrol-edilir-i/• http://bjclark.me/2009/08/nosql-if-only-it-was-that-easy/• http://reactivemongo.org/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×