[JAVA-1193] Java API only allows WriteResult.getN(), doesn't return nMatched, nUpserted, and nModified Created: 29/Apr/14  Updated: 30/Apr/14  Resolved: 30/Apr/14

Status: Closed
Project: Java Driver
Component/s: Write Operations
Affects Version/s: 2.12.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Hendy Irawan Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

When updating via Mongo Shell (MongoDB 2.6.0) we get 3 'n' numbers :

bippo:PRIMARY> db.salesOrder.update({formalId: '100000001'}, {'$unset': {formalIdTrie: ''}});
 
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })

However only `WriteResult.getN()` is provided by the Java API. From the mongo-java-driver 2.12.1 implementation :

    /**
     * Gets the "n" field, which contains the number of documents
     * affected in the write operation.
     * @return the number of documents modified by the write operation
     * @throws MongoException
     */
    public int getN(){
        return getLastError().getInt( "n" );
    }

is it correct? Since there seems to be no n field in the WriteResult object when observed via Mongo shell.



 Comments   
Comment by Jeffrey Yemin [ 30/Apr/14 ]

You can access the new fields for new by using bulk write operations. See DBCollection.initializeOrderedBulkWriteOperation(). It returns a BulkWriteResult with all the new fields.

Comment by Hendy Irawan [ 30/Apr/14 ]

jeff.yemin Thanks for explanation. In the meantime we'll be waiting for new WriteResult fields to be supported in Java API

Comment by Jeffrey Yemin [ 30/Apr/14 ]

Yes, this is correct. The getN method will return what you're seeing in the shell for "nModified". There is some translation going on in the driver to handle the introduction of write commands in 2.6 while still maintaining compatibility with older servers.

Comment by Hendy Irawan [ 29/Apr/14 ]

maybe related to JAVA-593

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