Hi Francesco,
Is this the recommended way to perform batch operation over millions of documents? Do exist any alternatives?
It’s hard to say what’s the “recommended” approach, since all cases are unique in their own way.
Having said that, if your updates is disruptive to your application performance, a possible solution is to limit the update to a subset of the collection at a time using a filtering criteria on the updateMany() command, and perform the updates on a non-busy period. Since the goal is to mutate every single document in the collection, minimizing application impact is probably the best direction.
For example, if your document contains a date field, you maybe able to select a range of date at a time e.g.:
db.collection.updateMany({date: <some limited range of date>} , {$unset: ...})
If you have your date field indexed, the operation should be faster as well. Is it not important to have indexes on the field to be unset.
If you still have questions about this, please post some example documents.
Best regards,
Kevin
Thank you, that is indeed a nice feature. I am going to upvote it.
My best,
Francesco Rivola