Repository navigation
fix(data): stop rebuilding text and 2dsphere indexes on every startup - #450
Merged
omegascorp merged 2 commits intoNov 9, 2026
Merged
Conversation
MongoDB reports text indexes as {_fts: 'text', _ftsx: 1} with weights and fills in default_language, language_override and index versions, so the existing index never matched the declared one and was dropped and recreated on each start.
Compare text indexes in their declared form and only compare server-defaulted options when they are declared.
Fixes modelence#449
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 329bf0e. Configure here.
MongoDB stores weight 1 for text fields without a declared weight, so compare undeclared fields as 1 instead of rebuilding the index.
omegascorp
approved these changes
Nov 9, 2026
omegascorp
left a comment
Collaborator
There was a problem hiding this comment.
Looks good, thank you
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #449
MongoDB lists text indexes as
{ _fts: 'text', _ftsx: 1 }plusweights, and fills indefault_language,language_overrideand the index versions on its own. So the existing index never matched what the Store declares, and it got dropped and rebuilt on every start.Now the existing text index is turned back into the declared shape before comparing, and those server-filled options are only compared when you actually declare them. Changing the fields or weights still rebuilds the index.
Tests: added 4 cases in store.test.ts (keeps an unchanged text index, keeps an unchanged 2dsphere index, rebuilds when text fields change, rebuilds when weights change). All data tests pass.
Note
Medium Risk
Touches startup index reconciliation logic; incorrect equivalence could skip needed rebuilds or still churn indexes, but behavior is covered by new tests and only affects index metadata comparison.
Overview
Fixes index reconciliation so text and 2dsphere indexes that already exist in MongoDB are not dropped and recreated on every app startup.
isSameIndexDefinitionnow normalizes MongoDB’s reported text index keys (_fts/_ftsxplusweights) back into the declared{ field: 'text' }shape before comparing keys. Server-filled options (default_language,language_override,textIndexVersion,2dsphereIndexVersion) are ignored unless the Store explicitly declares them, and implicit weight1on text fields matches partialweightsdeclarations.When text fields or weights actually change, reconciliation still drops and rebuilds the index. New unit tests cover unchanged text/2dsphere indexes, partial weights, and rebuild-on-change cases.
Reviewed by Cursor Bugbot for commit 15c0f21. Bugbot is set up for automated code reviews on this repo. Configure here.