Skip to content

fix(data): stop rebuilding indexes declared with unique: false, hidden: false or a simple collation - #470

Merged
omegascorp merged 1 commit into
modelence:mainfrom
poojagosika:fix/index-unstored-options
Nov 16, 2026
Merged

omegascorp merged 1 commit into
modelence:mainfrom
poojagosika:fix/index-unstored-options

Conversation

@poojagosika

@poojagosika poojagosika commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #469

MongoDB leaves unique: false, hidden: false and a simple collation out of the stored index, so isSameIndexDefinition never matched and createIndexes dropped and rebuilt those indexes on every startup.

  • A declared false for unique/hidden now matches when the stored index omits it.
  • A simple collation now matches a stored index with no collation.
  • Added 2 tests: the omitted options keep the index, and adding unique: true or a real collation still rebuilds it. The first fails without the fix.

Checked against MongoDB 7: before, the second startup dropped both indexes; after, nothing is dropped


Note

Low Risk
Changes are limited to index comparison logic in createIndexes, with tests covering both the no-op and rebuild paths; no auth or data mutation behavior is affected.

Overview
Index reconciliation now treats MongoDB’s omitted stored options as equivalent to explicit false or simple collation in code-defined indexes, so createIndexes no longer drops and rebuilds those indexes on every startup.

isSameCollation treats a missing stored collation as matching a declared { locale: 'simple' }. isSameIndexDefinition ignores unique: false and hidden: false on the desired index when the server metadata omits those fields.

Tests confirm unchanged indexes are kept when listIndexes omits those options, and that adding unique: true or a non-simple collation still triggers a rebuild.

Reviewed by Cursor Bugbot for commit 8901175. Bugbot is set up for automated code reviews on this repo. Configure here.

…n: false or a simple collation

MongoDB leaves these out of the stored index, so the declared index never matched and was dropped and rebuilt on every startup.

@omegascorp omegascorp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you for the PR poojagosika

@omegascorp
omegascorp merged commit e80ae80 into modelence:main Nov 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Indexes declared with unique: false, hidden: false or a simple collation are dropped and rebuilt on every startup

2 participants