C# .NET 6 Web Api with MongoDb, Swagger, basic CRUD operations

Spencer Thomason
2 min readJun 17, 2022

This is our series about Coding for Entrepreneurs! I firmly believe that even if you aren’t the one doing the coding in your organization, learning to code will help you to more effectively manage your team and your product! So I think every Entrepreneur should learn to code!

Today we are going to dig into our 3rd coding sample. We will use Visual Studio to build a simple Web Api using C# and now we are going to connect it to MongoDB — a good simple lightweight document storage database. So let’s dig in!

Code Sample for today: https://github.com/slthomason/StartupHakk/tree/main/03_WebApi_With_MongoDB

To install MongoDB: https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-windows/

This tutorial creates a web API that runs Create, Read, Update, and Delete (CRUD) operations on a MongoDB NoSQL database.

In this tutorial, you learn how to:

Configure MongoDB
Create a MongoDB database
Define a MongoDB collection and schema
Perform MongoDB CRUD operations from a web API
Customize JSON serialization

It ultimately depends on the technology you’re building on but in this series, we’ll be working on .Net/.Net CORE. For that, you either want to use Microsoft Visual Studio or Microsoft Visual Studio Code. Both of them can be downloaded for free from the official website for both Windows and macOS.

You can download both of them and see which one suits your needs. In this video, we’ll create a new project and create a simple Hello World application. It can act as a guide to get familiarized with different aspects of visual studio/code such as the solution explorer and properties.

Visual Studio vs Visual Studio Code

You can think of Visual Studio as a cookie-cutter solution that is jampacked with features and functionality. As Visual Studio is much more powerful, it works in most situations out of the box whereas Visual Studio Code can be considered a Lite version of it with lots of addons available which can ultimately make the two nearly identical. Some might even consider it as a “glorified text editor”. In comparison, Visual Studio does require more knowledge to be utilized to its true potential unlike Visual Studio Code which is more beginner-friendly however, Visual Studio does offer more precise control over everything. At the end of the day, it all comes down to personal preference.

--

--