title: How to set WriteConcern for very safe writes to MongoDB replica set in Java
body: <p>We have a requirement to write one particular bit of data to a mongo replica set, and be <em>really</em> sure that it's safe (this is a legal requirement). Is there a standard WriteConcern that encapsulates a write to disk on a majority of nodes? Something like MAJORITY_FSYNCED.</p>
  
  <p>The best I've come up with is the following - is this valid? 
  <code>
  WriteConcern replicaSetFsyscToMajority = new WriteConcern.Majority(0, true, false);
  </code></p>
  
  <p>Looking at the pre-defined levels in the Java driver's WriteConcern class, none of the existing levels seem to be quite what I'm after, as far as I can tell:</p>
  
  <p>FSYNCED means a secure write to disk on the primary only. (So a meltdown on the primary node could result in the write being lost)</p>
  
  <p>REPLICAS_SAFE seems to represent that the write has been acknowledged by at least 2 replicas, and written to <strong>memory</strong>, not necessarily to disk (so a power cut to the whole mongo replica set could lose the write). MAJORITY is similar - but to ((n/2) + 1) replicas.</p>
  
  <p>Supplementary notes/comments</p>
  
  <ul>
  <li>We're using the Java drivers 2.11.2 on Java 7.</li>
  <li>Obviously, for these super-safe writes, performance takes a hit, we're happy with this (or more accurately, our load is low enough that it is a premature optimisation).</li>
  <li>If we can't write to the db, we can retry, but if that fails, it is better* for us to abort the user's journey than to continue without the DB write,  :( Like I said, this is a legal requirement.</li>
  </ul>
  
  <p>* for a given definition of better!</p>
  
  <hr>
  
  <p>EDIT: What we've tried so far...</p>
  
  <p>We've tried using:</p>
  
  <pre><code>new WriteConcern.Majority(0, true, false)
  </code></pre>
  
  <p>and I can say that it doesn't throw any errors, (we can read and write, and all our tests pass), I have no idea if it is verifying writes to any great degree, and I haven't performance profiled it. </p>