Results 1 to 5 of 5

Thread: changes in "writeConcern" behaviour in RC1 ?

  1. #1
    Join Date
    May 2006
    Location
    Germany
    Posts
    33

    Question 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. #2
    Join Date
    Jul 2007
    Posts
    26

    Default

    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

  3. #3
    Join Date
    May 2006
    Location
    Germany
    Posts
    33

    Talking 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

  4. #4

    Default

    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.

  5. #5

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •