Duplicate Mongoose index on User.email and User.username

Abierto
#4,338 2 comentarios 0 reacciones 2 asignados Ver en GitHub

Los mantenedores suelen responder en 4 días

@yashgoyal0110 ya está trabajando en esto.

Desde el 4/11/2026.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
mongodb, typescript
Área
backend, database

Línea de trabajo

Start in server/models/user.ts, checking the field definitions around lines 15 and 24 and the schema indexes around lines 333–334. Reproduce the startup warning with a local MongoDB connection and inspect existing indexes and case-duplicate rows before changing the definitions. Done means startup has no duplicate-index warning and each field has one case-insensitive unique index, with existing deployments considered.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Bug
p5.js version

N/A this is a server-side (database model) issue, unrelated to the p5.js library version.

What is your operating system?

Mac OS

Web browser and version

N/A backend issue, happens at server startup before any browser is involved.

Actual Behavior

On server startup, Mongoose logs a duplicate-index warning:

Duplicate schema index on {"email":1} found. This is often due to declaring an index using both "index: true" and "schema.index()". Please remove the duplicate index definition.

The same happens for username.

In server/models/user.ts the fields are indexed twice:

  • username: { type: String, required: true, unique: true } (line 15) and email: { type: String, unique: true } (line 24) create a unique index via unique: true
  • lines 333–334 declare a second index on the same fields with a collation:
    userSchema.index({ username: 1 }, { collation: { locale: 'en', strength: 2 } });
    userSchema.index({ email: 1 }, { collation: { locale: 'en', strength: 2 } });

On top of the warning, the two indexes aren't equivalent. The unique: true index is case-sensitive and is the only one enforcing uniqueness; the collation index (meant to make lookups case-insensitive) is not unique. So although the model comments say "Email addresses should be case-insensitive unique" and findByEmailAndUsername queries with a collation, the database only enforces case-sensitive uniqueness case-insensitive uniqueness depends entirely on the app-level check at signup (which has a check-then-insert race).

Expected Behavior

No duplicate-index warning at startup, and a single case-insensitive unique index per field so the database itself enforces the case-insensitive uniqueness the code already assumes.

Suggested fix- move uniqueness onto the collation index:

// schema fields
username: { type: String, required: true },   // drop unique: true
email: { type: String },                        // drop unique: true

// bottom of file
userSchema.index({ username: 1 }, { unique: true, collation: { locale: 'en', strength: 2 } });
userSchema.index({ email: 1 }, { unique: true, collation: { locale: 'en', strength: 2 } });

(Existing deployments would need the old case-sensitive indexes dropped so the new ones get built, and any pre-existing case-duplicate rows cleaned up first.)

Steps to reproduce

Steps:

  1. Set up the project locally with a MongoDB connection (copy .env, point MONGO_URL at a running mongo).
  2. Start the server: npm start
  3. Watch the server logs on startup the "Duplicate schema index on {email:1}" warning appears (and the same for username).
Lenguaje dominante
JavaScript
Estrellas
1.7k
Forks
1.7k
Merge medio
7 d 1 h
PR fusionados (30 d)
13

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de processing/p5.js-web-editor

Todos los issues de processing/p5.js-web-editor

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.