[JAVA-524] Add reference to original object when inserting duplicate key Created: 23/Feb/12  Updated: 25/Jun/13  Resolved: 11/Mar/13

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

Type: New Feature Priority: Minor - P4
Reporter: themanatuf Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

RHEL 5, Java 1.6, Maven 2



 Description   

When inserting a duplicate document, it would be cool if the original ID could be returned with the DuplicateKey exception. Rather than querying for my document before inserting it, I'm simply inserting it and catching the DuplicateKey exception. I'd like to be able to add the ID to my "duplicate" object so I can continue processing without having to query again for it.



 Comments   
Comment by Scott Hernandez (Inactive) [ 23/Feb/12 ]

This isn't supported on the server unfortunately:

E11000 duplicate key error index: test.people.$_id_ dup key: { : ObjectId('4e683574bc4135eee514713f') }
> db.getLastErrorObj()
{
        "err" : "E11000 duplicate key error index: test.people.$_id_  dup key: { : ObjectId('4e683574bc4135eee514713f') }",
        "code" : 11000,
        "n" : 0,
        "connectionId" : 1777,
        "ok" : 1 }

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