title: MongoDB high Consistency
body: <p>I want to create a payment system and I choose mongodb for database
  I want to know how can I achieve high consistency? </p>
  
  <p>I want to use <strong>Multi-Document Transactions</strong> but when I have replica set , the secondaries node may have <strong>stale</strong> docs , and If I read from stale doc , My system is broken</p>
  
  <p>In mongodb docs , <a href="https://docs.mongodb.com/manual/replication/#read-operations" rel="nofollow noreferrer">https://docs.mongodb.com/manual/replication/#read-operations</a></p>
  
  <blockquote>
    <p>By default, clients read from the primary [1]; however, clients can specify a read preference to send read operations to secondaries. Asynchronous replication to secondaries means that reads from secondaries may return data that does not reflect the state of the data on the primary.</p>
  </blockquote>
  
  <p>AND</p>
  
  <blockquote>
    <p>[1]    (1, 2) In some circumstances, two nodes in a replica set may transiently believe that they are the primary, but at most, one of them will be able to complete writes with { w: "majority" } write concern. The node that can complete { w: "majority" } writes is the current primary, and the other node is a former primary that has not yet recognized its demotion, typically due to a network partition. When this occurs, clients that connect to the former primary may observe stale data despite having requested read preference primary, and new writes to the former primary will eventually roll back.</p>
  </blockquote>
  
  <p>Even if I force client to read from primary , In some circumstances two nodes in a replica set may transiently believe that they are the primary, So client may observe stale data </p>
  
  <p>How can I design a payment system in mongoDb? consistency is very important</p>