In this article, we will learn about working with MongoDB in ASP.NET Core. We will be building a WebAPI Project that can manage customer data. Along the way we will cover various concepts including Introduction to NoSQL Database, What is MongoDB, Installing MongoDB Locally and on the Cloud, Integrating with ASP.NET Core and much more. In general, you will be getting a complete working knowledge with MongoDB and probably set enough to start implementing MongoDB in your next ASP.NET Core Project. The source code of the application that we will be building is available here.
We will be working with ASP.NET Core 3.1 WebAPI, Visual Studio 2019 IDE and MongoDB. Let’s begin!
Table of Contents
If you are new to NoSQL Databases, it mean exactly what it sounds like. NOSQL or Non SQL Databases contrary to the SQL Databases, store the data in forms that not in any way similar to Relational Tables. A very common misconception is that, NOSQL Databases cannot store relationship data. It can store the relationship data as well, but just in a different way that is nothing similar to how SQL Databases works.
Querying a SQL Database may be complicated for specific usecases. Imagine having to search for a particular user data that is available only after Joining Multiple Tables. If the number of records are high, the query performance may be on the weaker side at times. With NOSQL Databases, you get to store all the user data under one document / dictionary. Thus, while querying, the application has to just look under one document. This can noticabley improve the performance.
Note that, this doesnt mean SQL Databases is no longer recommended. You could have both SQL and NOSQL Databases under a single application. An example of such an use case is , You could NOSQL Databases as a secondary Database that can be used to Search purposes as we know that it can outperform SQL DB.
The advantages with using NOSQL Databases are as follows.
Now, there a quite a lot of types of NOSQL Databases. This includes the following
#coding