Announcement Announcement Module
No announcement yet.
changes in "writeConcern" behaviour in RC1 ? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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: oDbException: norepl; nested exception is com.mongodb.MongoException: norepl
    Caused by: com.mongodb.MongoException: norepl
    at com.mongodb.CommandResult.getException(CommandResu
    at com.mongodb.CommandResult.throwOnError(CommandResu
    at com.mongodb.DBTCPConnector._checkWriteError(DBTCPC
    at com.mongodb.DBTCPConnector.say( :155)
    at com.mongodb.DBTCPConnector.say( :138)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLa
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLa
    at com.mongodb.DBCollection.insert( 57)
    at com.mongodb.DBCollection.insert( 87)
    at 6)
    at e$11.doInCollection(
    at e.execute(
    ... 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,

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

    <bean id="mongoTemplate" class=" 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 name="writeResultChecking" value="EXCEPTION" />

    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!



    • #3
      Thanks - that helped

      Thanks for the tip!

      Actually changing

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


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

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



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

        My bean was previously setup using

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

        Thanks again.


        • #5
          jira issue created