[JAVA-758] Write concern is behaving unexpectably Created: 12/Feb/13  Updated: 13/Feb/13  Resolved: 13/Feb/13

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: 2.9.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Brice Laurencin Assignee: Unassigned
Resolution: Done Votes: 0
Labels: driver, java, writeResult
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

$ uname -a
Linux 3.5.0-24-generic #37-Ubuntu SMP Thu Feb 7 01:50:30 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
$ mongo --version
MongoDB shell version: 2.0.6
$ mongod --version
db version v2.0.6, pdfile version 4.5
Tue Feb 12 18:53:04 git version: nogitversion
$ java -version
java version "1.7.0_13"
Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)


Attachments: Java Source File ExposingMongoStrangeBehavior.java    

 Description   

Hi,
I encounter strange behaviour regarding the writeResult.getN() returned value.

The first save to a DBCollection seems to be failing, writeResult.getN() being != 1, but in fact, it does save the object, a subsequent find() proves it (see the attache test class, the method theTest).

After a seemingly failled save, a second save actually return writeResult.getN() being == 1 (see theSecondTest).

Did I do/understood something wrong?

Thanks for your precious help!
Brice.



 Comments   
Comment by Brice Laurencin [ 13/Feb/13 ]

On this very test, it is an insert both times.

Anyway, I worked arround this behavior, thanks for your time!
Brice.

Comment by Jeffrey Yemin [ 13/Feb/13 ]

You can use that to determine whether the save call ended up inserting a new document or updating an existing one. n = 0 is an insert, n = 1 is an update

Comment by Brice Laurencin [ 13/Feb/13 ]

Thanks for your quick reply!

But then I don't get why the second call returns 1.

Comment by Jeffrey Yemin [ 12/Feb/13 ]

I believe that n is not set on inserts, only updates and removes, since it's only then that you don't necessarily know how many documents were updated/removed. If the insert/save failed, an exception will be thrown.

Generated at Thu Feb 08 08:53:00 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.