Announcement Announcement Module
Collapse
No announcement yet.
changes in "writeConcern" behaviour in RC1 ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • changes in "writeConcern" behaviour in RC1 ?

    Hello Spring Data MongoDB users,

    Today I updated my project to use spring data mongodb RC1 from
    the M4 version I used before.

    All my unit tests that try to save an object to mongodb now crash
    with the following exception:

    org.springframework.data.mongodb.UncategorizedMong oDbException: norepl; nested exception is com.mongodb.MongoException: norepl
    ...
    Caused by: com.mongodb.MongoException: norepl
    at com.mongodb.CommandResult.getException(CommandResu lt.java:87)
    at com.mongodb.CommandResult.throwOnError(CommandResu lt.java:121)
    at com.mongodb.DBTCPConnector._checkWriteError(DBTCPC onnector.java:131)
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java :155)
    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java :138)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLa yer.java:261)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLa yer.java:211)
    at com.mongodb.DBCollection.insert(DBCollection.java: 57)
    at com.mongodb.DBCollection.insert(DBCollection.java: 87)
    at com.mongodb.DBCollection.save(DBCollection.java:71 6)
    at org.springframework.data.mongodb.core.MongoTemplat e$11.doInCollection(MongoTemplate.java:774)
    at org.springframework.data.mongodb.core.MongoTemplat e.execute(MongoTemplate.java:368)
    ... 35 more


    As far as I tracked the problem down, it seems to be related to the the handling
    of the "writeConcern" setting of the underlying MongoTemplate. Anything
    other than the default will cause the exception above.

    I configured the writeConcern to be "SAFE", since i want to be informed
    about unique index violations immediately.
    Leaving the writeConcern setting with its default removes the exception
    but breaks my unit tests related to the unique index behaviour.

    How can I configure a writeConcern other than the default without getting
    an exception ? Is there something a am missing ?


    Any hints appreciated,
    Dirk

  • #2
    I set up my write concern in M5 as follows:

    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.Mongo Template">
    <constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
    <constructor-arg name="mongoConverter" ref="mappingConverter" />
    <property name="writeConcern">
    <util:constant static-field="com.mongodb.WriteConcern.SAFE" />
    </property>
    <property name="writeResultChecking" value="EXCEPTION" />
    </bean>

    I have not had any issues in M5. I also tried snap shot release for other issues, but I did not notice anything wrong with writeConcern.

    Hope that helps!

    BR//Bahman

    Comment


    • #3
      Thanks - that helped

      Thanks for the tip!

      Actually changing

      <property name="writeConcern" value="SAFE"/>

      to

      <property name="writeConcern">
      <util:constant static-field="com.mongodb.WriteConcern.SAFE" />
      </property>

      seems to be a difference. But spring does not complain when bootstrapping the application context. Strange.

      Regards,
      Dirk

      Comment


      • #4
        Thanks for this, solved my problems encountered from M4 to RC1.

        My bean was previously setup using

        <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.Mongo Template">
        <constructor-arg ref="mongoDbFactory"/>
        <constructor-arg ref="mappingConverter"/>
        <property name="writeConcern">
        <bean class="com.mongodb.WriteConcern">
        <constructor-arg index="0" value="1"/>
        </bean>
        </property>
        </bean>

        Thanks again.

        Comment


        • #5
          jira issue created
          https://jira.springsource.org/browse/DATAMONGO-408

          Comment

          Working...
          X