|
In the C# driver SafeMode can be set at different levels. 1. At the server level via the connection string: var connectionString = "mongodb://hostname/?safe=true;w=2;wtimeout=30s"; var server = MongoServer.Create(connectionString); 2. At the database level: var safemode = SafeMode.W2; // default timeout // or var safeMode = SafeMode.Create(2, TimeSpan.FromSeconds(30)); // 30 second timeout var database = server.GetDatabase("test", safeMode); 3. At the collection level: var collection = database.GetCollection("test", safeMode); 4. At the operation level:
var safeModeResult = collection.Insert(document, safeMode);
Each level inherits the setting from the level above it unless overridden. getLastError is called automatically when any SafeMode other than false is used. An exception is thrown if there was an error, otherwise the SafeModeResult has the information returned by GetLastError. See Also |

PLEASE POST QUESTIONS IN THE USER GROUPS FORUM. Post non-question comments and helpful hints here.
blog comments powered by Disqus