[SERVER-14801] duplicate key error should report field names as well as values Created: 06/Aug/14  Updated: 24/Apr/20  Resolved: 14/Sep/18

Status: Closed
Project: Core Server
Component/s: Index Maintenance, Usability
Affects Version/s: None
Fix Version/s: 4.1.4

Type: Improvement Priority: Minor - P4
Reporter: Jeffrey Yemin Assignee: Xiangyu Yao (Inactive)
Resolution: Done Votes: 2
Labels: asya, neweng, nyc
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-37070 All storage engines should show the c... Closed
is depended on by SERVER-37124 Retry full upsert path when duplicate... Closed
is depended on by SERVER-37532 Retry update on specific duplicate in... Closed
Duplicate
is duplicated by NODE-1130 Show full path of duplicate key error... Closed
is duplicated by SERVER-33567 Show full path of duplicate key error... Closed
Problem/Incident
causes PYTHON-1767 Doctests fails on unexpected keyPatte... Closed
Related
related to SERVER-4637 E11000 (duplicate key error) should r... Open
related to SERVER-3069 Add extra fields to getLastError outp... Closed
related to SERVER-19281 Add index name as a separate field on... Closed
is related to SERVER-33814 Include additional metadata as proper... Closed
is related to JAVA-1352 DuplicateKeyException should provide ... Closed
Backwards Compatibility: Fully Compatible
Sprint: Storage NYC 2018-09-24
Participants:
Case:

 Description   

Consider a compound index with a name:

db.test.ensureIndex( { a: 1, b : 1 }, { unique: true, name : 'index_1' }

A duplicate key error on that index reports this errmsg:

"errmsg" : "insertDocument :: caused by :: 11000 E11000 duplicate key error index: admin.test.$index_1  dup key: { : 1.0, : 2.0 }"

The dup key is a string that looks like JSON but is missing the field names. It would be easier for clients to understand the error message if the dup key contained the field names as well as the values, especially in the case of named indexes where the index name doesn't provide enough of a clue, e.g.

"errmsg" : "insertDocument :: caused by :: 11000 E11000 duplicate key error index: admin.test.$index_1  dup key: { a : 1.0, b : 2.0 }"

I'd also prefer that the index name be rendered without the collection name or the $. Clients know what collection they are using. and the $ is not part of the index name from the clients perspective.



 Comments   
Comment by Githook User [ 14/Sep/18 ]

Author:

{'name': 'Xiangyu Yao', 'email': 'xiangyu.yao@mongodb.com', 'username': 'xy24'}

Message: SERVER-14801 Add field names to duplicate key error messages
Branch: master
https://github.com/mongodb/mongo/commit/2072abc1824e633bb0b0fdf330fb40fe410d5092

Comment by Asya Kamsky [ 22/Feb/18 ]

Note that currently the message is:

"E11000 duplicate key error collection: test.users index: _id_ dup key: { : 2.0 }"

so the namespace/collection is shown separately.

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