[GODRIVER-1553] Add method to identify which key has duplicate value Created: 05/Apr/20  Updated: 07/Apr/20  Resolved: 07/Apr/20

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

Type: Task Priority: Major - P3
Reporter: Claudio Yanes Assignee: Divjot Arora (Inactive)
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Even if detecting it’s fairly simple to detect if the write failure was produced by a duplicated key, it’s not so simple to detect which key was duplicated because, as far as I’m concerned, the only way it’s extract it from the error message string, which is error  prone and can easily break with an driver update. So, I will be very happy to see a new method that easily allows to know the key at fault when this kind of error happens.



 Comments   
Comment by Divjot Arora (Inactive) [ 07/Apr/20 ]

Hi clausly4@gmail.com,

These error messages are actually generated by the MongoDB server. The driver does not do any processing here, except for taking the server's response and unmarshalling it into the proper error type (in this case likely a mongo.WriteException or mongo.BulkWriteException). It's not feasible for us to add a method to the driver for this because we wouldn't be able to guarantee that it works for all existing and future server versions.

You mentioned driver updates, so I also want to clarify that a driver update should not break your code if you decided to do this yourself because the driver will always relay the server's responses. I do recommend using a substring check (e.g strings.Contains() rather than a string equality check because the driver may decorate the server's response with some additional information if necessary.

Given this, I'm going to close this ticket. Feel free to leave a comment or open another ticket if you have any further questions.

– Divjot

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