mongodb system_error ai_generated partial

MongoServerError: can't drop index on system collection

ID: mongodb/cannot-drop-index-on-system-collection

Also available as: JSON · Markdown · 中文
72%Fix Rate
85%Confidence
1Evidence
2023-08-15First Seen

Root Cause

Attempted to drop an index on a system collection (e.g., system.views, system.profile) which is restricted by MongoDB's internal protections.

generic

中文

尝试删除系统集合(如 system.views、system.profile)上的索引,但 MongoDB 内部保护机制禁止此类操作。

Official Documentation

https://www.mongodb.com/docs/manual/reference/command/dropIndexes/#restrictions

Workarounds

  1. 70% success Use db.adminCommand({dropIndexes: 'admin.system.views', index: 'my_index_name'}) as a superuser, but only if absolutely necessary and after backing up the collection.
    Use db.adminCommand({dropIndexes: 'admin.system.views', index: 'my_index_name'}) as a superuser, but only if absolutely necessary and after backing up the collection.
  2. 75% success Disable the system collection's read-only flag temporarily by restarting mongod with --setParameter 'systemCollectionsReadOnly=false' (MongoDB 6.0+), then drop the index, then re-enable.
    Disable the system collection's read-only flag temporarily by restarting mongod with --setParameter 'systemCollectionsReadOnly=false' (MongoDB 6.0+), then drop the index, then re-enable.

中文步骤

  1. Use db.adminCommand({dropIndexes: 'admin.system.views', index: 'my_index_name'}) as a superuser, but only if absolutely necessary and after backing up the collection.
  2. Disable the system collection's read-only flag temporarily by restarting mongod with --setParameter 'systemCollectionsReadOnly=false' (MongoDB 6.0+), then drop the index, then re-enable.

Dead Ends

Common approaches that don't work:

  1. 95% fail

    Using db.collection.dropIndex() on a system collection with force:true ignores the error but corrupts internal metadata, leading to server crash or data loss.

  2. 80% fail

    Changing the collection name to a non-system prefix (e.g., 'my_views') and re-creating indexes doesn't fix the original system collection; the error persists.