So I was wondering if its possible to delete all records from all collections based on a filter in one query
No I don’t believe such a method exists today. You would have to go into each collection, and execute the delete command in each of them. Something like:
for x in [list of collection names]:
db[x].deleteMany( <some condition> )
However note that you’ll also need to cover the case of interruptions with the command (replica set elections, network issues, etc.) where there’s a possibility that not all collections were processed. This would lead to some orphaned documents that may need extra cleanup steps.
I imagine if such a command exist, it will be a pretty dangerous command. Also depending on the number of collections you have, it could have a non-trivial running time that’s dfifficult to predict.
Hope this helps!