Build a Simple RESTful CRUD API in .NET 5 (ASP.Net Core) with MongoDB in 2021

Setting up MongoDB

docker run --name mongodb -v /my/own/datadir:/data/db -p 27017:27017 --restart unless-stopped -d mongo
docker container list results

Create a new project.

Creating a new project
Directory structure after creating the project.

Install the required Nuget Packages

Installed Packages

Configuring the MongoDB Connection


Setting up our domain classes.

TodoList class

Setting up our Mongo Database Services


Setting up our RESTful API Controller


Starting & Trying out our API

Swagger Documentation

Creating a TodoList

Response Body

Retrieving All TodoLists

Response Body
My Updated TodoList Response

Retrieving a specific TodoList

Id Input Field
Request Response

Deleting a specific TodoList

Id Input Field

Short Coding Tutorials for .NET & NodeJS

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store