[SERVER-34841] Cannot create multiple indexes with the same pattern but different options Created: 04/May/18  Updated: 10/May/18  Resolved: 04/May/18

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

Type: Bug Priority: Major - P3
Reporter: Ralf Kistner Assignee: Ramon Fernandez Marina
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-25023 no way to index the same fields with ... Closed
Operating System: ALL
Participants:

 Description   

Background:

In our production system, we have an unique index, that used the wrong partialFilterExpression. This caused the query planner to not use this index when querying for documents.

To fix this issue, we want to create the correct index, and only drop the previous index afterwards, to ensure we still have consistency.

However, MongoDB prevents us from creating another index with the same pattern:

// Old (wrong) index
db.users.createIndex({"sessions._id": 1}, {name: 'session_id', unique: true, partialFilterExpression: {'sessions': {"$exists" : true}}})
 
// New index
db.users.createIndex({"sessions._id": 1}, {name: 'session_id2', unique: true, partialFilterExpression: {'sessions._id': {"$exists" : true}}})
 
{{ "ok" : 0, "errmsg" : "Index with pattern: { sessions._id: 1.0 } already exists with different options", "code" : 85}

 

Our only solution currently is to first drop the old index, then create the new one. However, this results in a period of time where the unique constraint is not enforced, which can potentially cause issues.

This may be a duplicate of https://jira.mongodb.org/browse/SERVER-22194, but that issue had a different use case, and was closed as a duplicated of a different issue.

 



 Comments   
Comment by Asya Kamsky [ 10/May/18 ]

For future reference, there is an ugly work-around that does not leave you with no constraint and that is to add a new index with an extra trailing field (a dummy field that's not set in any documents) then drop original index, recreate the new index and then drop the temporary index.   

 

Comment by Ramon Fernandez Marina [ 04/May/18 ]

Thanks for your report ralf@embarkmobile.com, this one is a duplicate of a different ticket, SERVER-25023. Please tune to SERVER-25023 for updates and feel free to comment on it and vote for it.

Regards,
Ramón.

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