Definition
The deleteMany() method in MongoDB is used to delete all documents that match a specified filter condition. It is useful when you need to remove multiple records from a collection with a single command.
Steps to Delete Multiple Documents Using deleteMany() in MongoDB
1). Open the MongoDB Shell using mongosh.
2). Select the database using use database_name.
3). Check the existing documents using find().
4). Use the deleteMany() method with a filter condition.
5). Execute the deleteMany() command to remove all matching documents.
6). Verify the deletion using find().
Example
use studentdb
db.students.deleteMany(
{ course: "Java" }
)
db.students.find()