Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Like this? Share it with your network

Share

Introduction to mongo db

  • 9,402 views
Uploaded on

This is the revised MongoDB presentation I gave to the Austin .NET User Group on November 8, 2010. It is an introduction to MongoDB and all its features. Audio available on my blog at......

This is the revised MongoDB presentation I gave to the Austin .NET User Group on November 8, 2010. It is an introduction to MongoDB and all its features. Audio available on my blog at http://chrisedwards.dreamhosters.com

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
9,402
On Slideshare
8,701
From Embeds
701
Number of Embeds
13

Actions

Shares
Downloads
549
Comments
0
Likes
21

Embeds 701

http://www.nosqldatabases.com 400
http://www.chrisedwards.dreamhosters.com 217
http://chrisedwards.dreamhosters.com 39
http://feeds.feedburner.com 17
http://pinterest.com 9
http://rg443blog.wordpress.com 6
http://www.pinterest.com 5
http://www.udemy.com 3
http://o1.c4tw.net 1
http://paper.li 1
http://static.slidesharecdn.com 1
http://webcache.googleusercontent.com 1
http://architester.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide











  • This is a test note

  • Collection
    - Documents can be anything
    - Advantageous if they are similar
  • Prejoined relationship
  • Prejoined relationship
  • Prejoined relationship
  • Prejoined relationship
  • Prejoined relationship
  • Prejoined relationship
  • Prejoined relationship
  • Prejoined relationship
  • Prejoined relationship
  • Prejoined relationship
  • Prejoined relationship
  • Prejoined relationship
  • Prejoined relationship


























Transcript

  • 1. Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P Chris Edwards h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m
  • 2. About Me Chris Edwards Senior Developer at BancVue Ltd. Email: ChrisEdwards357@gmail.com Blog: http://chrisedwards.dreamhosters.com Twitter: @cedwards Github: http://github.com/chrisedwards (Sample code for this talk is posted) h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 3. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 4. What is No-SQL? h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 5. What is No-SQL? “Next Generation Databases mostly addressing some of the points: being non-relational, distributed, open-source and horizontal scalable. ... schema-free, easy replication support, simple API, eventually consistent ...” - nosql-database.org h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 6. What is No-SQL? “Next Generation Databases mostly addressing some of the points: being non-relational, distributed, open-source and horizontal scalable. ... schema-free, easy replication support, simple API, eventually consistent ...” - nosql-database.org • Non-Relational • Schema-Free • Distributed • Replication Support • Open-Source • Simple API • Horizontally Scalable • Eventually Consistent h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 7. What is No-SQL? It’s about using the right tool for the job. • Not all systems have the same data needs. • Sql is not the only option, nor is it always the best one. • Consider all options carefully and choose wisely. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 8. What is No-SQL? It’s about using the right tool for the job. • Not all systems have the same data needs. • Sql is not the only option, nor is it always the best one. • Consider all options carefully and choose wisely. Not Only SQL h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 9. What is No-SQL? It’s about using the right tool for the job. • Not all systems have the same data needs. • Sql is not the only option, nor is it always the best one. • Consider all options carefully and choose wisely. Not Only SQL It’s not about flaming SQL. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 10. What is No-SQL? It’s about using the right tool for the job. • Not all systems have the same data needs. • Sql is not the only option, nor is it always the best one. • Consider all options carefully and choose wisely. Not Only SQL It’s not about flaming SQL. Its about opening our minds to new technologies. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 11. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 12. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 13. What is MongoDB? • Document-oriented database - Uses JSON (BSON actually) • Schema-free • Performant - Written in C++ - Full index support - No transactions (has atomic operations) “Mongo only pawn in game of life” - Memory-mapped files (delayed writes) • Scalable - Replication - Auto-Sharding • Commercially supported (10gen) - Lots of documentation h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 14. Other Features of MongoDB • Document-based queries - Flexible document queries expressed in JSON/Javascript. • Map Reduce - Flexible aggregation and data processing. - Queries run in parallel on all shards. • GridFS - Store files of any size easily. • Geospatial Indexing - Find object based on location. (i.e. find closest n items to x) • Many Production Deployments h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 15. Other Features of MongoDB • Supported Platforms - OSX - Linux - Solaris - Windows - FreeBSD h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 16. MongoDB Basic Concepts Document - Analogous to a row in RDBMS - Represented as JSON (BSON) - Hierarchical - Can reference other documents h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 17. MongoDB Basic Concepts Document Collection - Analogous to a row in RDBMS - Analogous to a table in RDBMS - Represented as JSON (BSON) - Collection of documents - Hierarchical - Documents can by anything - Can reference other documents - Advantageous if they are similar h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 18. MongoDB Basic Concepts Embedding - Analogous to a foreign key - Think “pre-joined relationship”. - Clearer conceptual model. - DDD Aggregate Root - Can be - Sub Objects - Collections h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 19. MongoDB Basic Concepts Embedding - Analogous to a foreign key - Think “pre-joined relationship” - Clearer conceptual model. - DDD Aggregate Root - Can be - Sub Objects - Collections References - Analogous to a foreign key - Think “relationship” h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 20. MongoDB Basic Operations Querying All the following queries will find the document. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 21. MongoDB Basic Operations Querying All the following queries will find the document. By property value h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 22. MongoDB Basic Operations Querying All the following queries will find the document. By property value By embedded object property value h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 23. MongoDB Basic Operations Querying All the following queries will find the document. By property value By embedded object property value With comparison operators h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 24. MongoDB Basic Operations Querying All the following queries will find the document. By property value By embedded object property value With comparison operators Values in collections (implicit “in”) h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 25. MongoDB Basic Operations Indexing h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 26. MongoDB Basic Operations Indexing On property value h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 27. MongoDB Basic Operations Indexing On property value On embedded object property h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 28. MongoDB Basic Operations Indexing On property value On embedded object property On embedded collections h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 29. MongoDB Basic Operations Indexing On property value On embedded object property On embedded collections On multiple keys h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 30. MongoDB Basic Operations Inserting h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 31. MongoDB Basic Operations Updating Using Query/Modify/Save h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 32. MongoDB Basic Operations Updating Using Query/Modify/Save • Requires each object to be loaded in memory. • Requires multiple hits to the database. • Very inefficient. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 33. MongoDB Basic Operations Updating Using Atomic Updates h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 34. MongoDB Basic Operations Updating Using Atomic Updates • Analogous to transactions. • Requires only one trip to the database. • Operations are atomic. • Can perform multiple operations at once. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 35. MongoDB System Components h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 36. MongoDB System Components mongod.exe The database server h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 37. MongoDB System Components mongod.exe mongo.exe The database server The interactive shell h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 38. MongoDB System Components mongod.exe mongo.exe The database server The interactive shell mongos.exe The sharding router h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 39. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 40. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 41. Installing MongoDB 1. Download MongoDB. www.mongodb.com/downloads 2. Extract it. 3. Create the data folder. usually /data/db -or- C:datadb 4. Run mongod.exe h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 42. Installing MongoDB 1. Download MongoDB. www.mongodb.com/downloads 2. Extract it. 3. Create the data folder. usually /data/db -or- C:datadb 4. Run mongod.exe That’s it! h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 43. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 44. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 45. Accessing MongoDB via the Shell • Inserting a document into a collection. • Querying a collection. • Modifying a document. • Deleting a document. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 46. Accessing MongoDB via the Shell • Inserting a document into a collection. • Querying a collection. • Modifying a document. • Deleting a document. Lets do it! h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 47. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 48. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 49. Accessing MongoDB via C# • mongo-csharp-driver - 10gen-supported driver • mongodb-csharp driver - Most mature driver for C#. - Includes LINQ support • NoRM driver - Using NoRM for strongly typed access. - Also has LINQ support h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 50. Accessing MongoDB via C# • mongo-csharp-driver - 10gen-supported driver • mongodb-csharp driver - Most mature driver for C#. - Includes LINQ support • NoRM driver - Using NoRM for strongly typed access. - Also has LINQ support For more information and/or drivers for other languages, check out www.mongodb.org h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 51. Accessing MongoDB via C# Demo h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 52. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 53. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 54. Accessing MongoDB via REST • To enable basic REST interface, use --rest command line. - mongod.exe --rest • REST interface uses port +1000. - http://127.0.0.1:28017/database/collection/ - http://127.0.0.1:28017/database/collection/?filter&Field=Value • Full REST support is provided by the Sleepy.Mongoose lib. - http://github.com/kchodorow/sleepy.mongoose h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 55. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 56. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 57. MongoDB Replication • Master-Slave - Master - mongod.exe --master - Slave - mongod.exe --source <master url>:<master port> - Slave can use --slavedelay <delay in seconds> to have a rolling backup. • Replica Pairs (obsolete) • Replica Sets (Suggested Approach) - Full Failover support - Supports more than 2 servers in a replica cluster - Data center and rack aware - Can have passive set members (slaves) that are never primary • Master-Master (limited) - Both masters are also configured as slaves - Safe for insert, delete by id, and any queries - Unsafe for concurrent updates of single object h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 58. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 59. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 60. MongoDB Auto-Sharding: Features h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 61. MongoDB Auto-Sharding: Features • Based on a defined shard key. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 62. MongoDB Auto-Sharding: Features • Based on a defined shard key. • Auto-balances as shard servers are added or removed. - Can go from single master to sharded system with zero downtime. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 63. MongoDB Auto-Sharding: Features • Based on a defined shard key. • Auto-balances as shard servers are added or removed. - Can go from single master to sharded system with zero downtime. • Failover handled through replica sets. (each shard replicated) h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 64. MongoDB Auto-Sharding: Features • Based on a defined shard key. • Auto-balances as shard servers are added or removed. - Can go from single master to sharded system with zero downtime. • Failover handled through replica sets. (each shard replicated) • Map Reduce queries are run in parallel across shards. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 65. MongoDB Auto-Sharding: Architecture • Shard Servers - Instance of mongod.exe --shardsvr - Optionally configured with a replication set for failover. • Config Servers - Instance of mongod.exe --configsvr - Usually a group of 3. System is up so long as 1 config server is running. • Shard Routers - Instance of mongos.exe --configdb <config server>:<config port> - Acts like mongod.exe to clients. - Can be on the same box as a shard server. - Can run on appserver to reduce traffic. h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 66. MongoDB Auto-Sharding: Architecture Sample Logical Architecture h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 67. MongoDB Auto-Sharding: Architecture Sample Physical Architecture h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 68. MongoDB Auto-Sharding: Configuration Startup Servers • Startup Shard Servers - mongod.exe --shardsvr • Startup Config Servers - mongod.exe --configsvr • Startup Shard Routers - mongos.exe --configdb <config server>:<config port> Configure Cluster • Add Shards to the Cluster - Execute the following command for each shard using either the driver or shell. - db.runcommand( { addshard : “<shard server>:<shard server port>” } ); • Enable Sharding on the Databases to Shard - db.runcommand( { enablesharding : “<dbname>” } ); • Specify Collections to Shard - db.runcommand( { shardCollection : “<collection>”, key : <key pattern> } ); h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 69. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 70. MongoDB Session Roadmap • What is the NoSQL Movement? • What is MongoDB? • Installing • Using the Mongo Shell • Accessing MongoDB via C# - Basic Driver (mongodb-csharp driver) - Using Linq - Using NoRM for strong typing • Accessing MongoDB via REST • Replication • Sharding h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P
  • 71. Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P ? h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m
  • 72. Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P ? h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m
  • 73. About Me Chris Edwards Senior Developer at BancVue Ltd. Email: ChrisEdwards357@gmail.com Blog: http://chrisedwards.dreamhosters.com Twitter: @cedwards Github: http://github.com/chrisedwards (Sample code for this talk is posted) h t t p : / / c h r i s e d wa r d s . d r e a m h o s t e r s . c o m Introduction to MongoDB A No-SQL Persistence Alternative A U S T I N - . N E T - U S E R - G R O U P