Table of Contents....5
About the Author....11
Acknowledgments....12
Introduction....13
Chapter 1: Choosing MongoDB....14
Relational vs. NoSQL Databases....14
What Is a Relational Database?....14
Advantages of a Relational Database....17
Simplicity....17
Normalization....17
Atomicity, Consistency, Isolation, Durability (ACID)....18
Data Accuracy....19
Disadvantages of a Relational Database....19
Performance....19
Scalability....19
Flexibility....20
Cost....20
Complexity....20
What Is a NoSQL Database?....20
Key-Value Database....21
What Are the Main Features of a Key-Value Database?....21
What Are Examples and Use Cases for Key-Value Databases?....21
What Are the Advantages of a Key-Value Database?....23
What Are the Disadvantages of a Key-Value Database?....23
Wide-Column Database....24
Examples and Use Cases for Wide-Column Databases....24
Advantages of Wide-Column Databases....24
Disadvantages of Wide-Column Databases....25
Graph Database....25
What Are the Main Features of a Graph Database?....25
What Are Examples and Use Cases of a Graph Database?....26
What Are the Advantages of a Graph Database?....27
What Are the Disadvantages of a Graph Database?....27
Document Database....28
What Are the Main Features of a Document Database?....28
What Are Examples and Use Cases of a Document Database?....28
What Are the Advantages of a Document Database?....30
What Are the Disadvantages of a Document Database?....31
So Why Choose MongoDB?....31
Summary....31
Chapter 2: What Is MongoDB?....32
The Beginning of MongoDB....32
MongoDB Server (On-Premises)....34
Enterprise Advanced....34
Community Edition....34
MongoDB Atlas....35
Database....35
Replica Sets....35
Sharding....36
Aggregation....38
Serverless....41
Data Federation....41
Data Lake....42
Search....42
Atlas CLI....42
Atlas App Services....43
Triggers....43
Functions....43
Authentication....44
Data API....45
Realm....45
Device Sync....46
Charts....46
Summary....47
Chapter 3: Creating an Account....49
Creating Your MongoDB Account....49
Google Account....50
GitHub Account....52
Create a New Account....53
Finalizing Your New Account....56
Summary....58
Chapter 4: Creating Your First Cluster and Loading Sample Dataset....59
Creating Your First Cluster....59
Loading Sample Dataset....64
Summary....67
Chapter 5: Browsing Your Data....68
Atlas UI....68
Reading Data....68
Creating or Updating Data....71
Deleting Data....74
Mongosh....75
Reading Data....78
Creating Data....79
Updating Data....79
Deleting Data....80
MongoDB Compass....80
Reading Data....81
Creating, Updating, or Deleting Data....84
Aggregation Builder....85
Visual Studio Code Extension....88
Reading Data....90
Creating Data....91
Updating Data....92
Deleting Data....92
Data API....93
Reading Data....94
Creating Data....95
Updating Data....96
Deleting Data....96
Drivers....97
GraphQL....98
Reading Data....102
Creating, Updating, and Deleting Data....102
Summary....104
Chapter 6: Creating the Application....105
Tooling....106
.NET SDK – CLI....106
Integrated Development Environment (IDE)....109
Visual Studio 2022....109
JetBrains Rider....110
Cleaning Up....112
Summary....112
Chapter 7: Adding MongoDB....114
Add the MongoDB NuGet Package....114
Store Connection String....115
Fetch Your Connection String from Atlas....115
Add the Connection String to Our Application....117
Create a MongoDB Client....118
Retrieving a List of Databases....119
Final Code....120
Summary....122
Chapter 8: Creating and Interacting with Documents from Code....123
Adding the Model....123
Creating the Service....125
Updating to Use the Service....126
Adding Create Methods to the Service....126
Adding Read Methods to the Service....127
Adding an Update Method to the Service....127
Adding a Delete Method to the Service....128
Creating a Controller....128
Final Code....132
Program.cs....132
Game.cs....133
GamesDatabaseService.cs....134
GamesController.cs....135
Summary....137
Chapter 9: Testing the Endpoints....138
Creating Documents....139
Creating One Document....139
Creating Many Documents....140
Reading Documents....141
Reading All Documents....141
Reading One Document....142
Updating a Document....143
Deleting a Document....144
Summary....145
Chapter 10: Schema Validation....146
Data Modeling....146
Validating for Required Fields....147
Handling Invalid Documents....149
Specifying Data Types for Fields....150
Specifying Allowed Values for a Field....151
Applying Validation to Existing Documents....153
Allowing Invalid Documents on an Ad Hoc Basis....155
Finding Invalid Documents to Update....155
Schema Anti-Patterns....158
Summary....159
Chapter 11: What Next?....160
Adding a UI....160
Using .NET MAUI and Atlas Device SDKs....161
Visualizing Your Data....161
Searching Your Data....162
Atlas Search....162
Atlas Vector Search....162
Play with the Sample Data....163
Learn More....163
Summary....164
This book is a tutorial on MongoDB customized for developers working in Microsoft .NET 6, .NET 7, and beyond. It explains the differences between relational database systems and the document model supported by MongoDB, and shows how to build .NET applications that run against a MongoDB database, especially one in the cloud.
Author Luce Carter kicks things off by teaching you how to determine when to use a document database versus a relational engine. After that, she walks you through building a Microsoft .NET project combining the MongoDB Atlas cloud database as a service solution with a .NET. application. In the process, you will learn how to create, read, update, and delete data in MongoDB from any .NET project.
You will come away from this book with a solid understanding of MongoDB’s Developer Data Platform and how to use it from your .NET applications. You’ll be able to connect to MongoDB in the cloud and take advantage of the flexibility and scalability that MongoDB’s document storage model provides, and you’ll understand how to craft your applications to run using document storage and the MongoDB database engine.
.NET developers who are looking for an alternative to relational databases, and those looking for a flexible and scalable document storage solution for use from .NET applications. Additionally, anyone wanting to learn MongoDB in the context of .NET and C# will benefit from this book.