{"record":{"id":"7a5a2932a103d171","repo":"RocketChat/Rocket.Chat","slug":"error-dropping-redundant-indexes-continuing","errorCode":null,"errorMessage":"Error dropping redundant indexes, continuing...","messagePattern":"Error dropping redundant indexes, continuing\\.\\.\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"apps/meteor/server/startup/migrations/v312.ts","lineNumber":16,"sourceCode":"import { LivechatRooms, Rooms, Subscriptions, Users } from '@rocket.chat/models';\n\nimport { addMigration } from '../../lib/migrations';\n\naddMigration({\n\tversion: 312,\n\tasync up() {\n\t\ttry {\n\t\t\tawait Promise.allSettled([\n\t\t\t\tLivechatRooms.col.dropIndex('v.token_1'),\n\t\t\t\tRooms.col.dropIndex('t_1'),\n\t\t\t\tSubscriptions.col.dropIndex('rid_1'),\n\t\t\t\tUsers.col.dropIndex('active_1'),\n\t\t\t]);\n\t\t} catch (error: unknown) {\n\t\t\tconsole.warn('Error dropping redundant indexes, continuing...');\n\t\t\tconsole.warn(error);\n\t\t}\n\t},\n});\n","sourceCodeStart":1,"sourceCodeEnd":21,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/startup/migrations/v312.ts#L1-L21","documentation":"Migration v312 drops four single-field indexes made redundant by compound ones. Note the code shape: Promise.allSettled never rejects, so the surrounding try/catch (and this console.warn) is effectively dead code — individual dropIndex failures (index absent, missing privilege) are captured as rejected results inside the fulfilled array and silently ignored. The migration continues regardless, which is intentional: leftover redundant indexes only cost minor write overhead.","triggerScenarios":"Re-running the migration after a partial run (MongoDB returns IndexNotFound / ns not found); database user lacking dropIndex privilege on managed MongoDB; deployments where indexes were renamed or never existed.","commonSituations":"Restored backups with differing index sets; Atlas/managed MongoDB roles restricting index operations; manually re-run migrations.","solutions":["No action required for correctness — redundant indexes remaining only adds minor write overhead","To actually clean up, connect with sufficient privileges and drop 'LivechatRooms v.token_1', 'Rooms t_1', 'Subscriptions rid_1', 'Users active_1' manually","If you maintain this code, log the allSettled results instead of the unreachable catch"],"exampleFix":"// before: try/catch around Promise.allSettled never fires\ntry {\n\tawait Promise.allSettled([Rooms.col.dropIndex('t_1')]);\n} catch (error) {\n\tconsole.warn('Error dropping redundant indexes, continuing...', error);\n}\n// after: inspect each outcome explicitly\nconst results = await Promise.allSettled([Rooms.col.dropIndex('t_1')]);\nfor (const result of results) {\n\tif (result.status === 'rejected') console.warn('dropIndex failed:', result.reason);\n}","handlingStrategy":"validation","validationCode":"// drop only indexes that actually exist\nasync function dropIndexIfExists(collection: { col: { dropIndex(name: string): Promise<unknown>; listIndexes(): { toArray(): Promise<{ name?: string }[]> } } }, name: string) {\n\tconst indexes = await collection.col.listIndexes().toArray();\n\tif (indexes.some((idx) => idx.name === name)) {\n\t\tawait collection.col.dropIndex(name);\n\t}\n}","typeGuard":null,"tryCatchPattern":"const results = await Promise.allSettled([Rooms.col.dropIndex('t_1')]);\nfor (const result of results) {\n\tif (result.status === 'rejected') console.warn('dropIndex failed:', result.reason);\n}","preventionTips":["Remember Promise.allSettled never rejects — a surrounding try/catch cannot see individual failures","Run migrations with a DB user that has index privileges, or accept and manually drop leftovers later","Treat redundant-index leftovers as cosmetic; verify with listIndexes instead of re-running migrations blindly"],"tags":["mongodb","migrations","indexes","startup"],"backgroundTag":"index-drop-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}