I want to delete data from multiple collection based on ids received using match query from aggregation .
Currently in python i am doing like this but it is taking a lot of time to execute .
motor is used
data = studentSource.aggregate([
{"$match": {'primary_source.utm_source': source_name}},
{'$project': {'student_id': 1, '_id': 0}}
])
students = [stud async for stud in data]
if len(students) != 0:
for i in range(len(students)):
await studentsPrimaryDetails.delete_many({'_id': students[i]['student_id']})
await studentSecondaryDetails.delete_many({'student_id': students[i]['student_id']})
await studentTimeline.delete_many({'student_id': students[i]['student_id']})
await studentApplicationForms.delete_many({'student_id': students[i]['student_id']})
await queries.delete_many({'student_id': students[i]['student_id']})
await leadsFollowUp.delete_many({'student_id': students[i]['student_id']})
await lead_details.delete_many({'student_id': students[i]['student_id']})
await studentSource.delete_many({'primary_source.utm_source': source_name})
```
Is there any improvement can be done to execute this much faster . Is bulkWrite() useful . But i have to delete data from multiple collection