[CSHARP-1236] Non-unique key error handling Created: 08/Apr/15 Updated: 05/Apr/19 Resolved: 08/Apr/15 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 2.0 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Aristarkh Zagorodnikov | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
It appears that MongoCollection<TDocument>.InsertOneAsync throws a MongoWriteException which does not have any direct information about the kind of error happened, including non-unique key constraint violation. I checked the source and even single inserts are done via bulk write operations, which are inherently not very good at passing single-request error information. I was expecting MongoDuplicateKeyException to be thrown in case of such violation. |
| Comments |
| Comment by Craig Wilson [ 08/Apr/15 ] |
|
Yes, probably should have been moved. Alas, too late now. |
| Comment by Aristarkh Zagorodnikov [ 08/Apr/15 ] |
|
Oh, Craig, I'm okay with this (already added an IsDuplicateKeyError extension method for our toolset), it's just the MongoDuplicateKeyException that took me off the right course. Maybe it should be moved to legacy part of the driver? |
| Comment by Craig Wilson [ 08/Apr/15 ] |
|
We opted not to throw a MongoDuplicateKeyException because, well, why is it more special? Instead, we opted for a common consistent way to check for certain types of known errors. |
| Comment by Aristarkh Zagorodnikov [ 08/Apr/15 ] |
|
P.S. In understand that there is a WriteError field available and we can check the category, it's just the MongoDuplicateKeyException that is defined in non-legacy part of the driver, but is not used. |