Spring values ​​mongodb write-concern

In spring, I have the following mongo configurations configuration:

<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 the different options of the recording numbers, which are related to the recording problem, like no one else, normal, safe, etc.

Can we assume that the display of the record number in writeconcern is indicated below?

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

The following link provided good help for setting mongo parameters in spring, but not enough for record number values: How to configure the MongoDB Java driver for use in MongoOptions?

+5
source share
2 answers

- - "w", , , , w > 1.

FSYNC_SAFE write-fsync (true false), JOURNAL_SAFE , , Spring , .

, , :

       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());

, Fsync ( ), W ( int).

+3

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>

, .

+1
source

All Articles