Skip to content

Collation indexes (incl. users handle/email) are dropped and rebuilt on every startup #420

Closed

Description

@poojagosika

What happens

On every app startup, createIndexes drops and recreates any index declared with a collation, even when nothing changed. This includes the built-in unique users indexes on handle and emails.address (src/auth/db.ts).

Why

MongoDB's listIndexes reports a collation fully expanded, with every option plus the ICU version:

{ locale: 'en', caseLevel: false, caseFirst: 'off', strength: 2, numericOrdering: false, alternate: 'non-ignorable', maxVariable: 'punct', normalization: false, backwards: false, version: '57.1' }

The code declares only { locale: 'en', strength: 2 }. isSameIndexDefinition in src/data/store.ts deep-compares the two, so they never match and the index is treated as changed.

Impact

With the default background creation mode, the drop runs under the lock and the rebuild runs later in the background. Until it finishes:

  • nothing enforces case-insensitive handle/email uniqueness (the signup race the emails.address index exists to prevent);
  • collation lookups fall back to collection scans;
  • if a duplicate slips in, the rebuild fails and is only logged as a warning.

How to check

Run db.users.getIndexes() on any existing app: the _modelence_handle_1 and _modelence_emails.address_1 collations come back expanded, and the indexes are recreated on each restart.

Fix

PR #419 compares only the collation fields the index declares, with a regression test that fails on main.

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