حذف بسیاری از اسناد(Delete Many Documents)
برای حذف بیش از یک سند، از
روش delete_many()
.
اولین پارامتر روش delete_many()
یک شی پرس و جو است که تعریف می کند کدام اسناد را حذف کنید.
مثال
Delete all documents were the address starts with the letter S:
import pymongo
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["mydatabase"]
mycol = mydb["customers"]
myquery = { "address": {"$regex": "^S"} }
x = mycol.delete_many(myquery)
print(x.deleted_count, " documents
deleted.")