[CDRIVER-709] Define mongoc_error_code_t value for "duplicate key error" Created: 17/Jun/15  Updated: 19/Oct/16  Resolved: 11/Oct/16

Status: Closed
Project: C Driver
Component/s: docs, errors
Affects Version/s: None
Fix Version/s: 1.5.0

Type: New Feature Priority: Major - P3
Reporter: Ulticom Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Server OS = CentOS 6.5
Client OS = CentOS 6.5
mongo C driver version = 1.1.7
mongo DB version = 2.6.5
Our application uses the mongo C driver to issue all the configuration commands to the server.
Our application uses 32 threads to interface to the mongo servers.
We use SSL and authorization.
We are in the Eastern Time Zone of USA (New Jersey)


Issue Links:
Depends
depends on CDRIVER-644 bson_error_t's "code" is often wrong Closed
is depended on by PHPLIB-225 Ensure that users can distinguish dup... Closed
Duplicate

 Description   

I would like to code our application to trap on this bson_error_t returned by mongoc_collection_insert():

domain: 11
code: 11000
message: insertDocument :: caused by :: 11000 E11000 duplicate key error index: DSC_service1_DBNAME.TABLENAME.$_id_  dup key: { : "SDF" }

However I don't want to put "magic numbers" in our code, like this:

if (error.code == 11000)

I would like to code it like this:

if (error.code == SOME_ENUMERATION_FOR_DUPLICATE_KEY)

Where do I find the enumeration?

Thanks,
Barry



 Comments   
Comment by Githook User [ 11/Oct/16 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-709 add MONGOC_ERROR_DUPLICATE_KEY
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/90c72a86fa944a4045cca1ba80bd95d117db99f9

Comment by A. Jesse Jiryu Davis [ 25/Aug/15 ]

Reopening, the C Driver should provide applications a nice way to check for duplicate key err, as other drivers do, once CDRIVER-644 is sorted out.

Comment by Jeremy Mikola [ 17/Jun/15 ]

The C driver's error domains and codes are defined in src/mongoc/mongoc-error.h; however, this is not an exhaustive list of server-side error codes.

You may want to consult docs/errors.md in the server repository as well.

Generated at Wed Feb 07 21:10:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.