-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Fully Compatible
Currently, enabling safe mode (SafeMode.Enabled == true) leads to MongoSafeModeException to be thrown if the command failed. While it's a fine thing to do generally, throwing the exception if the error is expected (think unique constraint violations for example) isn't a good idea in the terms of performance (in .NET under Windows, throwing an exception takes a lot of time, hurts cache, etc.).
I propose a new flag to be added to SafeMode – SafeMode.Permissive. It should default to false, cannot be set to true unless SafeMode.Enabled is also true (like SafeMode.W can't be set to nonzero value while SafeMode.Enabled isn't true), and the checks that lead to an exception to be thrown inside the MongoConnection.SendMessage() method should only be done if SafeMode.Permissive is false.
The proposed solution completely preserves backwards compatibility and greatly aids if one wants to examine and handle MongoDB error responses on his own without incurring the performance penalty of catching exceptions while a simple error code check would suffice.