Skip to content

fix: remove duplicate Mongoose index on username and email fields#4016

Open
Ambuj123554 wants to merge 1 commit intoprocessing:developfrom
Ambuj123554:fix/duplicate-mongoose-index-username
Open

fix: remove duplicate Mongoose index on username and email fields#4016
Ambuj123554 wants to merge 1 commit intoprocessing:developfrom
Ambuj123554:fix/duplicate-mongoose-index-username

Conversation

@Ambuj123554
Copy link
Copy Markdown

Issue:

Fixes #3752

When running the backend locally, Mongoose throws duplicate index
warnings for both the username and email fields on startup.
This was caused by having both unique: true in the schema field
definition AND a separate userSchema.index() call for the same
fields, resulting in two index definitions for each field.

Demo:

No UI changes — this is a backend fix. The Mongoose warnings no
longer appear on server startup after this fix.

Changes:

  • Removed unique: true from the username field definition
  • Removed unique: true from the email field definition
  • Uniqueness and case-insensitive collation is now handled solely
    by the existing userSchema.index() calls at the bottom of the
    file, which already include the correct collation settings

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • has no test errors (npm run test) — note: npm run test
    fails on Windows due to NODE_ENV syntax, unrelated to this fix
  • has no typecheck errors (npm run typecheck)
  • is from a uniquely-named feature branch and is up to date
    with the develop branch.
  • is descriptively named and links to an issue number — Fixes Duplicate Mongoose Index Warning for username field on Server Startup #3752
  • meets the standards outlined in the accessibility guidelines

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.

Duplicate Mongoose Index Warning for username field on Server Startup

2 participants