In this example we will show how to delete more than one document using the delete_many() method in Python MongoDB.
Source Code
from pymongo import MongoClient
client = MongoClient("localhost", 27017)
db = client["mydatabase"]
collection = db["us_state"]
query = {"Capital": {"$regex": "^D"}}
a = collection.delete_many(query)
print(a.deleted_count, "documents have been deleted")
Output:
2 documents have been deleted