Skip to content

Text and 2dsphere indexes are dropped and rebuilt on every startup #449

Closed

Description

@poojagosika

What happens
Every app start drops and recreates each text and 2dsphere index declared in a Store, even when nothing changed. While a text index is rebuilding, $text queries fail ("text index required for $text query"), and $near/$geoWithin queries fail the same way for 2dsphere. On large collections the rebuild also makes startup slow.

Why
isSameIndexDefinition in packages/modelence/src/data/store.ts compares what the code declares with what listIndexes reports, but MongoDB reports these indexes differently:

  1. A text index declared as { title: 'text' } comes back as { _fts: 'text', _ftsx: 1 }, with the fields in weights, so isSameIndexKey never matches.
  2. MongoDB fills in options the code doesn't declare: weights, default_language, language_override and textIndexVersion for text, and 2dsphereIndexVersion for 2dsphere. These are in COMPARABLE_INDEX_OPTION_FIELDS, so isDeepStrictEqual fails.

Same family as #420 (collation indexes).

Expected
Unchanged text and 2dsphere indexes are left alone on startup.

main @ c5ba748

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions