I found that some methods of the official MongoDB C# driver use SafeMode
and return SafeModeResult
. What is this SafeMode
and how do I use it? It would be great to see some use cases - for example, a use case with the RemoveAll
method of a MongoCollection
.
Safemode is only relevant when writing to the db.
For speed, if safemode is off and a write operation fails the driver doesn't wait around to care. Net effect is no exception gets thrown and you don't know you have an error.
Safemode set to on will force the driver to wait for a success confirmation, and if an error occurred will throw an exception.
Use safemode for data you care about (user accounts, orders, etc).
Don't use safemode for data that isn't essential (logging, usage stats etc)
MongoDB's default behavior is to have safemode off.