[SERVER-55738] Enhance error messaging when index creation results in an existing index having the same name Created: 02/Apr/21  Updated: 29/Oct/23  Resolved: 20/Apr/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.0.0-rc0

Type: New Feature Priority: Major - P3
Reporter: Michael Gargiulo Assignee: Yuhong Zhang
Resolution: Fixed Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Backwards Compatibility: Fully Compatible
Sprint: Execution Team 2021-05-03
Participants:

 Description   

For convenience, the helper method to create an index does not require that a user specify a name for the index. If a name is unspecified, one is generated in the driver by concatenating the names of the indexed fields and the sort order, e.g. an index on

{"a": 1}

will get a default name "a_1".

The shell method db.collection.createIndex appears to have identical behavior from my testing.

This can present problems in cases where a user creates multiple indexes in a collection with the same key pattern, as the generated names clash. A user who does something like:

db.foo.createIndex({a: 1})
db.foo.createIndex({a: 1}, {collation: 'de'}) 

Will get an error back saying "An existing index has the same name as the requested index". This is confusing as the user never specified a name for either index.

We should enhance the error messaging when "An existing index has the same name as the requested index" error is generated to ensure users will better diagnose and triage the problem. Perhaps we can consider something like: "when index names are not specified they are auto generated and can cause conflicts please refer to our documentation"



 Comments   
Comment by Githook User [ 19/Apr/21 ]

Author:

{'name': 'Yuhong Zhang', 'email': 'danielzhangyh@gmail.com', 'username': 'YuhongZhang98'}

Message: SERVER-55738 Enhance error messaging when index creation results in an existing index having the same name
Branch: master
https://github.com/mongodb/mongo/commit/85df0bf614fc6eb5286ef7c020f00d0ff0fb21d9

Generated at Thu Feb 08 05:37:19 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.