-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Index Maintenance
-
None
-
ALL
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.
- duplicates
-
SERVER-25023 no way to index the same fields with two different partial index filters
- Closed