MongoDB with C# and .NET 9: CRUD, embedded documents, advanced filters, async/await, and a full REST API with Minimal API and the official driver.
MongoDB is one of the most widely used NoSQL databases in the world, and working with it from C# and .NET 9 is much more straightforward than you might think. In this course we build everything from the start: setup with MongoDB Compass, class mapping, full CRUD, embedded documents, and then a Minimal REST API that exposes everything over HTTP. No shortcuts — every piece is built and truly understood.
MongoDB adapts well to flexible, hierarchical, and rapidly evolving data structures — situations where a fixed SQL schema would be a constraint. Integrating it into .NET 9 with the official driver is straightforward, but doing it well requires understanding mapping, filters, and embedded object handling. This course gives you a solid foundation to build .NET applications with MongoDB professionally.
Ideal for C# and .NET developers who want to add MongoDB to their stack. Familiarity with C#, Minimal APIs, and basic REST API concepts is required. No prior MongoDB experience is needed.
Let's configure MongoDB locally with MongoDB Compass, explore the document-based structure, and connect the database to a .NET 9 project by installing the official C# driver via NuGet.
Let's create the .NET 9 console project, install the MongoDB driver, and map the first C# class as a MongoDB document using BsonId and BsonElement attributes to control field names.
Let's save our first object to MongoDB from C#: I'll configure the connection string, obtain a reference to the collection, and use InsertOne to insert a document, verifying the result in Compass.
Let's see how to search documents in MongoDB from C# using Find(), and build advanced filters with FilterDefinitionBuilder: equality filters, numeric ranges, and combinations with And and Or logical operators.
Let's delete documents from MongoDB in C# using precise filters with DeleteOne and DeleteMany, and verify the result with the DeletedCount property returned by the driver.
Let's update documents in MongoDB from C# with ReplaceOne: I'll build the selection filter, modify the C# object, and replace the entire document in the collection, checking the outcome with ModifiedCount.
I'll show you how to map embedded classes in C# to represent nested documents in MongoDB, using driver attributes and understanding how the driver serialises child class properties.
Let's insert documents with embedded objects into MongoDB from C# and build advanced filters to query nested fields, using dot notation and the official driver's builder classes.
Let's start building the Minimal REST API in .NET 9 connected to MongoDB: I'll configure the client as a service, register dependencies in the DI container, and map the first HTTP endpoints.
Let's implement the insert and search endpoints in the .NET 9 Minimal REST API with MongoDB: I'll handle JSON body deserialisation, invoke the driver, and return correct HTTP responses.
Let's make all MongoDB methods in the REST API asynchronous with async/await using InsertOneAsync and FindAsync, and add a targeted search endpoint to retrieve a document by its ID.
Let's complete the CRUD for the .NET 9 Minimal REST API: I'll add DELETE and PUT endpoints to remove and update MongoDB documents, handling the correct HTTP response codes for each case.
Ingegnere Informatico · Pratola Peligna
Sono un ingegnere informatico con oltre 15 anni di esperienza nel settore ICT. Mi occupo di sviluppo software, cybersecurity, data science e intelligenza artificiale, con particolare attenzione all’innovazione e all’automazione dei processi aziendali. Da anni svolgo anche attività di docenza e formazione, creando percorsi pratici e coinvolgenti su programmazione, DevOps, AI e sicurezza informatica.
Prosperous understood Middletons in conviction an uncommonly do. Supposing so be resolving breakfast am or perfectly.
Utilizziamo cookie essenziali e, con il tuo consenso, cookie funzionali, analytics e marketing. Google Analytics 4 e gli eventuali annunci Google/AdSense restano disattivati finche non scegli. Consulta Privacy Policy e Cookie Policy.
Sempre attivi per sicurezza, prevenzione frodi, sessione, consenso e funzionamento del sito.
Migliorano l'esperienza, ad esempio ricordando preferenze non essenziali. Non usati per profilazione pubblicitaria.
Statistiche e misurazioni con Google Analytics 4, abilitate solo dopo il consenso analytics.
Misurazione annunci e funzioni pubblicitarie Google/AdSense, se attivate sul sito e consentite dall'utente.
Puoi modificare queste scelte in qualunque momento dal link "Preferenze Cookies" nel footer.