MongoDB multi update consistency
The documentation states


  When a single write operation modifies multiple documents, the modification of each document is atomic, but the operation as a whole is not atomic


Multi-row rollback is one of those things which are foregone in the NoSQL world, sadly.

That same link mentions the $isolated operator. This may be of some help, depending on the use case and topology.

Also documented is the so-called "two phase commit" pattern. This may require application changes, however, so may not be practical.

Five million rows isn't a silly-big number. Would it be possible to arrange an application outage until the writes succeed, with continuous retries? Maybe run the write application on the same hardware as Mongo so the network is no longer an issue.