SlideShare una empresa de Scribd logo
1 de 73
Introduction to MongoDB
                           A No-SQL Persistence Alternative
C E N T R A L - T E X A S - . 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
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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 be 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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
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
CENTRAL-TEXAS-.NET-USER-GROUP
Introduction to MongoDB
          A No-SQL Persistence Alternative
CENTRAL-TEXAS-.NET-USER-GROUP
                                             ?
                                             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
CENTRAL-TEXAS-.NET-USER-GROUP
                                             ?
                                             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
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
CENTRAL-TEXAS-.NET-USER-GROUP

Más contenido relacionado

Destacado

Back to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentBack to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentMongoDB
 
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)MongoDB
 
Beyond the Basics 1: Storage Engines
Beyond the Basics 1: Storage EnginesBeyond the Basics 1: Storage Engines
Beyond the Basics 1: Storage EnginesMongoDB
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...MongoDB
 
Back to Basics, webinar 4: Indicizzazione avanzata, indici testuali e geospaz...
Back to Basics, webinar 4: Indicizzazione avanzata, indici testuali e geospaz...Back to Basics, webinar 4: Indicizzazione avanzata, indici testuali e geospaz...
Back to Basics, webinar 4: Indicizzazione avanzata, indici testuali e geospaz...MongoDB
 
Back to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLBack to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLMongoDB
 
OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialSteven Francia
 
Mongo db data-models guide
Mongo db data-models guideMongo db data-models guide
Mongo db data-models guideDeysi Gmarra
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsMongoDB
 
Advanced Schema Design Patterns
Advanced Schema Design PatternsAdvanced Schema Design Patterns
Advanced Schema Design PatternsMongoDB
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationMongoDB
 
Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)
Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)
Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)MongoDB
 

Destacado (13)

Back to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production DeploymentBack to Basics Webinar 6: Production Deployment
Back to Basics Webinar 6: Production Deployment
 
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
MongoDB Schema Design (Event: An Evening with MongoDB Houston 3/11/15)
 
Beyond the Basics 1: Storage Engines
Beyond the Basics 1: Storage EnginesBeyond the Basics 1: Storage Engines
Beyond the Basics 1: Storage Engines
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
 
Back to Basics, webinar 4: Indicizzazione avanzata, indici testuali e geospaz...
Back to Basics, webinar 4: Indicizzazione avanzata, indici testuali e geospaz...Back to Basics, webinar 4: Indicizzazione avanzata, indici testuali e geospaz...
Back to Basics, webinar 4: Indicizzazione avanzata, indici testuali e geospaz...
 
MongoDB for Developers
MongoDB for DevelopersMongoDB for Developers
MongoDB for Developers
 
Back to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLBack to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQL
 
OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB Tutorial
 
Mongo db data-models guide
Mongo db data-models guideMongo db data-models guide
Mongo db data-models guide
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
 
Advanced Schema Design Patterns
Advanced Schema Design PatternsAdvanced Schema Design Patterns
Advanced Schema Design Patterns
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
 
Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)
Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)
Developing with the Modern App Stack: MEAN and MERN (with Angular2 and ReactJS)
 

Último

Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 

Último (20)

Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 

Updated Introduction to MongoDB

  • 1. Introduction to MongoDB A No-SQL Persistence Alternative C E N T R A L - T E X A S - . 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 be 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 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 CENTRAL-TEXAS-.NET-USER-GROUP
  • 71. Introduction to MongoDB A No-SQL Persistence Alternative CENTRAL-TEXAS-.NET-USER-GROUP ? 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 CENTRAL-TEXAS-.NET-USER-GROUP ? 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 CENTRAL-TEXAS-.NET-USER-GROUP

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. This is a test note\n
  13. \n
  14. Collection\n - Documents can be anything\n - Advantageous if they are similar\n
  15. Prejoined relationship\n
  16. Prejoined relationship\n
  17. Prejoined relationship\n
  18. Prejoined relationship\n
  19. Prejoined relationship\n
  20. Prejoined relationship\n
  21. Prejoined relationship\n
  22. Prejoined relationship\n
  23. Prejoined relationship\n
  24. Prejoined relationship\n
  25. Prejoined relationship\n
  26. Prejoined relationship\n
  27. Prejoined relationship\n
  28. Prejoined relationship\n
  29. Prejoined relationship\n
  30. Prejoined relationship\n
  31. Prejoined relationship\n
  32. Prejoined relationship\n
  33. Prejoined relationship\n
  34. Prejoined relationship\n
  35. Prejoined relationship\n
  36. Prejoined relationship\n
  37. Prejoined relationship\n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n