Why NoSQL and why MongoDB?
We explore the history of NoSQL databases and why they are becoming so popular, so quickly. We discuss the various categories of NoSQL databases including document databases, key-value stores, column-store databases, and graph databases. While these databases initially seem to have little in common, we will examine a common thread that flows between them. Next, we dig into MongoDB including why it’s the industry leader, the techniques it uses to become immensely scalable, and why it makes life much easier and simpler for development teams.
The shell and 'native' commands
MongoDB from .NET
Accessing MongoDB from .NET applications is easy and familiar to most .NET developers. The main query language in C# is LINQ (Language Integrated Query). Much of the functionality will be familiar to anyone with Entity Framework or NHibernate experience. However, there some gotchas (both for execution and performance) and this lesson will ensure you get the most out of MongoDB via .NET. There is also a second API built upon the atomic operators of MongoDB ($set, $push, etc.) which truly leverages the full power of MongoDB and its aggregate-level atomicity. We will explore this API from C# as well.
Designing entities in MongoDB (and document databases more generally) is very different than 3rd-normal-form from SQL tables. To be successful with MongoDB, you will need to master this skill. Getting your entity design correct is key to high performance and flexible applications. We will start by discussing some foundational OOD background on these rich documents and how you can leverage them for transactional safety. There are inherent limitations to documents (e.g. total size) and this lesson covers how work within those limits. We will talk about modeling relationships between data (embedding, foreign keys, data duplication). Finally, we discuss how to correctly deal with binary data and large data elements in MongoDB entities.
Indexing and profiling
Simply put, indexes are the single biggest contributor (or culprit) for extremely high performance MongoDB deployments and applications. This lesson will ensure your applications use indexes to full advantage. We will cover how to create indexes and the assorted types (simple, multi-key, compound, unique, sparse, and hashed indexes). You will see how to add indexes to subdocuments for high performance deep queries. In practice, finding the queries that need optimized can be tricky, especially when there is a translation layer in the middle such as LINQ and an ORM. You will see how to use profiling to find the slow queries (note that in MongoDB 10ms is a slow query). We will then use MongoDB’s explain method to see the query plan and determine which index (if any) is used.
Advanced C# serialization
The MongoDB C# driver (MongoDB’s terminology for their client libraries) has a vast set of options which customize and control exactly how C# classes are converted to and from documents. Understanding these serialization options is key to working with MongoDB successfully from .NET. We will explore topics such as dealing with case-sensitivity, dates and time zones, and evolving schemas as our application evolves. We will see how to omit default or null values to save storage space. We will use MongoDB’s support of initialization to easily manage circular references. You will learn how to work with inheritance within a single collection and more.
Working directly with documents in C#
Documents are central to MongoDB as you would expect for a document database. In this lesson, you will learn that C# has excellent support for working directly with these untyped BSON documents. BSON (binary JSON) documents appear in many places. LINQ queries are internally translated to BSON documents. C# objects are serialized to and from BSON documents. They are the key to working with MongoDB in a truly schemaless manner (should you choose to do so).
GridFS - A file system within MongoDB
MongoDB has a facility to store, classify, and query files of virtually unlimited size (binary data, text data, etc.). This lesson will introduce GridFS and show you how to work with it from C#. We will upload, download, and list files in GridFS. We will create custom metadata definitions (classes) and store them within our GridFS files which can then be used for rich reporting and querying that does not exist in standard file systems. We will alert you to a few pitfalls that lurk within GridFS and show you how to fill them in and avoid any trouble. Finally, we look at how GridFS is particularly well suited for web applications which the files (images, etc.) can be cached on the client-side.
The aggregation framework in MongoDB allows you to execute rich queries and transformations on the server (potentially scaled out across shards). While normal queries leverage documents in the exact structure, aggregation (similar to map-reduce) is much more flexible. It can transform, group, and query data as well as act as a data pipeline on the server. In this lesson, you will learn to choose between aggregation and queries. We will build aggregations from LINQ and directly in BSON.
Server administration for developers
Being successful with MongoDB means you must keep it running smoothly. This lesson is designed to ensure that everyone on the team has enough knowledge of the admin side of MongoDB for that purpose. You will learn how to setup MongoDB as a Windows Service / System Daemon. We will discuss various backup strategies (using mongodump / mongorestore, MMS backup, and more) as well as potential tradeoffs associated with these strategies. You will learn how to use mongostat, mongotop, MMS, and other tools to diagnose and monitor MongoDB’s performance.
Replication is key to MongoDB’s fault tolerance. It can also be used for data locality across data centers, scaled-out reads, offsite backups, reporting without performance degradation, and more. In this lesson we will start by learning how to create a replicate set and how to access primary and secondary replicas from our applications. You will learn about potential ‘eventual consistency’ issues you may encounter when scaling reads and how to mitigate any issues from them. We will discuss how our applications can automatically fail-over if there is a problem with the primary server. Finally we will configure hidden and delayed replicas for non-core application services.
Security and permissions
Security and data go hand-in-hand. You will learn how to enable security in MongoDB. We will explore how to create and manage user accounts and how to grant and revoke roles to users. You will see that users can be database-wide or server-wide users and we will discuss how to create and manage both. You will learn about basic auditing in MongoDB and how to implement practices which enhance security for MongoDB. Finally we’ll end this lesson by exploring major security features coming in the next version of the server.