5

I have the following core mongo options configuration in spring:

<mongo:mongo host="${db.hostname}" >
  <mongo:options
    connections-per-host="40"
    threads-allowed-to-block-for-connection-multiplier="1500"
    connect-timeout="15000"
    auto-connect-retry="true"
    socket-timeout="60000"
    write-number="1"
    write-fsync="false"/>
</mongo:mongo>

What I want to know is about different write-number options which is relevant to write concern like none, normal, safe etc.

Can I assume the mapping of write-number to writeconcern as below?

NONE: -1
NORMAL: 0
SAFE: 1 (default)
FSYNC_SAFE: 2
REPLICAS_SAFE: 3
JOURNAL_SAFE: 4
MAJORITY: 5  

Following link has provided a good help to set mongo options in spring, but not specific enough for write-number values: How to configure MongoDB Java driver MongoOptions for production use?

Community
  • 1
  • 1
inkriti
  • 1,335
  • 3
  • 12
  • 8

2 Answers2

3

The write-concern number is the value of "w" which maps to the number of replicas that the write must propagate to before being considered successful when w > 1.

FSYNC_SAFE maps to setting write-fsync (true or false) and since JOURNAL_SAFE is also a boolean value, I suspect there is a similar boolean setting in Spring but I couldn't find it in any of their docs.

If you have everything installed to test this out empirically, just try several configurations and check the actual setting of the resultant write concern with something like:

       WriteConcern wc = new WriteConcern(); // should get your default write concern
       System.out.println(wc.getJ());
       System.out.println(wc.getFsync());
       System.out.println(wc.getW());

That should show you Journal setting, Fsync setting (both boolean), W (as an int).

Asya Kamsky
  • 39,247
  • 5
  • 96
  • 124
1

You can confiture write-concern="ACKNOWLEDGED".

<mongo:mongo id="replicaSetMongo" replica-set="${mongo.replicaSetSevers}" />
    <mongo:db-factory dbname="${mongo.dbname}" mongo-ref="replicaSetMongo" write-concern="ACKNOWLEDGED" />
    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
        <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
    </bean>

Hope this can help.

lxiaodao
  • 11
  • 1