[CSHARP-593] C# MongoUrlBuilder SafeMode should support w: majority Created: 08/Oct/12  Updated: 20/Mar/14  Resolved: 09/Oct/12

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.6.1
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Chad Kreimendahl Assignee: Unassigned
Resolution: Done Votes: 0
Labels: Windows, connection, driver, replication
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Currently the SafeMode type only supports Fsyncs, W1-4 and True/False. The integer for W1-4 should also allow "majority" as supported by mongod.

From documentation: A good combination for highly critical writes is j:true and w:"majority".



 Comments   
Comment by Chad Kreimendahl [ 08/Oct/12 ]

I ended up using a method similar to your first two lines. We don't typically include any options on the standard connection string, because we create two types of connections in our base class, one for data that must absolutely be read from a primary and one that is less concerned about the immediacy of data (for reporting or status, or other less time sensitive information).

Feel free to close this issue. I think I'll be asking next for w:majority to work in situations where you are not in a replica set... where "majority" is just 1 (the same as total servers)

Comment by Robert Stam [ 08/Oct/12 ]

Using journal:true and w:majority is already supported.

You can set it on the connection string like this:

var connectionString = "mongodb://username:password@localhost/?safe=true;journal=true;w=majority";

or in code using SafeMode and MongoServerSettings like this:

var safeMode = new SafeMode(true) { Journal = true, WMode = "majority" };
var serverSettings = new MongoServerSettings { SafeMode = safeMode };
var server = MongoServer.Create(serverSettings);

Note that since C# is a strongly typed language, the W property of SafeMode only accepts integer values. When using string values as modes (instead of integers) use the new WMode property of SafeMode instead. W and WMode are mutually exclusive, setting one clears the other.

Comment by Chad Kreimendahl [ 08/Oct/12 ]

I might actually suggest we replicate (partially) the Java WriteConcern:

http://api.mongodb.org/java/2.9.1/com/mongodb/WriteConcern.html

Generated at Wed Feb 07 21:37:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.