Bulk.remove() or bulkWrite(delete:{}) | Which one is efficient?

In my application, I need to delete very huge amount of data at a single time by running a query. I need some optimized solution. I read here BulkOperations delete is very effiencient when companritive with deleteMany() function. Even in these we have two options. Which one is very optimised? Bulk.remove() or bulkWrite(delete:{})?

I would be very surprise if there are huge differences between the different approaches. You mentioned

The total amount of work is more or less the same in all approaches. And with huge amount of data, you will end up being I/O bound anyway to update the permanent storage of your collection and its indexes.

If you can specify a single query that matches all documents to delete, you should be using deleteMany with that single query. If you need multiple queries, a bulkWrite with one deleteMany per query is your safe bet.

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.