-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Tools and Replicator
-
7
Problem
With --convertLegacyIndexes enabled, mongorestore skips any index whose key pattern matches an index it has already kept (convertLegacyIndexes in mongorestore/restore.go, restored in TOOLS-4501). The comparison is key-pattern-only (bsonutil.IsIndexKeysEqual): index options and partialFilterExpression are ignored.
Modern servers accept multiple indexes with the same key pattern when their specs differ in options such as unique, partialFilterExpression, or collation. Verified on an 8.0 replica set: both indexes are created, even when submitted in a single createIndexes batch. So while the flag is on, one index of such a pair is silently skipped (only an Always-level "Skipping..." log line) and the restore reports success. Because IndexCatalog.GetIndexes iterates a map, which of the two survives is nondeterministic, so a restore can silently drop a unique constraint.
This affects every index in the restored collection while the flag is on, not just indexes whose key values were rewritten.
Why the dedup exists
The skip was added in TOOLS-2645 for the legacy key collapse: after conversion, the keys foo: "", foo: 1.0, and foo: 1 all become foo: 1 with otherwise identical specs, and the server rejects the batch:
Index already exists with a different name: foo_
That case still errors on 8.0, so the dedup itself remains necessary — it just over-applies.
Suggested fix
In convertLegacyIndexes, skip an index only when its key pattern is equal to an already-kept index and its options (ignoring name, ns, v, background) and partialFilterExpression are equal. Otherwise keep the index and let the server decide whether the specs are distinct; an option difference outside the ignored set then surfaces as a server error instead of a silent skip.
Add a regression test: a dump with same-key indexes differing in unique plus one legacy key spelling, restored with --convertLegacyIndexes — assert both indexes are created.
References
- Found by the Copilot review of the
TOOLS-4501PR: PR #1282 - The behavior predates
TOOLS-4350(the flag removal) and was reintroduced along with the flag inTOOLS-4501.
- is related to
-
TOOLS-4501 Bring back the --convertLegacyIndexes flag
-
- Closed
-