From the course: MongoDB C# Developer Associate Cert Prep

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Deleting documents in C# applications

Deleting documents in C# applications - MongoDB Tutorial

From the course: MongoDB C# Developer Associate Cert Prep

Deleting documents in C# applications

- Welcome. In this video, you'll learn how to delete one or more documents in a MongoDB collection by using the DeleteOne and DeleteMany methods and their Async methods. To delete a single document from a collection, we use the DeleteOne method on a Mongo collection instance. The DeleteOne method accepts a query filter that matches the document we want to delete. There are two ways to specify the document or documents that you want to delete. You can use either LINQ or the Builders class. If you're using a C# class to define you our MongoDB documents, LINQ is the more robust approach. If you're using BsonDocuments to represent your data, then you will use the Builders class. Let's go through a few examples. In this example, we define a MongoDB collection object called AccountsCollection. Then, with the DeleteOne method, on our AccountsCollection instance, we use LINQ to specify the account ID of the document that we…

Contents