PHeinze
unread,Feb 3, 2012, 3:14:03 PM2/3/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongodb-user
Hi,
when I try to insert a duplicate through this code:
<em>
try {
coll.findAndModify( queryId( document ).and( "p.revision" ).is( document.getRevision() ).get(),
new BasicDBObject( "$set", mods ) );
}
}
catch ( MongoException e )
{
</em>
it correctly throws an Exception. But I can't retrieve the correct
error code through .getCode() (it's always -5). Sadly I can't cast to
CommandFailure the Subclass which is thrown as this is package
private. Do I miss something or is the class wrongly private?
The Exception I catch is following:
<em>
com.mongodb.CommandResult$CommandFailure: command failed [command
failed [findandmodify] { "serverUsed" : "pheinze-0830:27017" ,
"lastErrorObject" : { "err" : "E11000 duplicate key error index:
test.address.$ns_1_t_1_p.doc_id_1 dup key: { : \"__nn__\", : \"N\", :
\"testPutPKTwice\" }" , "code" : 11000 , "n" : 0 , "connectionId" :
44 , "ok" : 1.0} , "errmsg" : "E11000 duplicate key error index:
test.address.$ns_1_t_1_p.doc_id_1 dup key: { : \"__nn__\", : \"N\", :
\"testPutPKTwice\" }" , "ok" : 0.0}
</em>
I know that I could call getlasterror and retrieve from there the
correct error code, but I don't feel comfortable with this solution as
the correct exception is already present but not accessable.
Thanks for your help